0
votes

My main issue is with the void OnMouseOver. Unity doesn't want to acknowledge the names "square" and "i". I can't write individual code for each game object because I have about 50 objects this code needs to apply to. I need to have a specific number pop up when I hover over a square. I'm not sure if the void OnMouseOver should be in the void Start or not, but when it was outside of it there were even more errors. Any advice is greatly appreciated! Thanks!

using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using System.IO;

public class HeaterRead : MonoBehaviour
{
    // Start is called before the first frame update
    void Start()
    {
        using (var reader = new StreamReader(@"C:\Users\labom\Documents\Work 
    Files\Heater_Main_Output.csv"))
        {
            List<float> listTi = new List<float>();
            List<float> listVe = new List<float>();
            List<float> listTe = new List<float>();
            while (!reader.EndOfStream)
            {
                var line = reader.ReadLine();
                var values = line.Split(',');

                listTi.Add(float.Parse(values[0]));
                listVe.Add(float.Parse(values[2]));
                listTe.Add(float.Parse(values[3]));
                line = reader.ReadLine();
            }

           // temperature minimum = 300F;
           // temperature maximum = 720F;

            Mathf.Lerp(0, 1, (listTe[0] / 420F) - 0.71F);


            List<GameObject> listS = new List<GameObject>();

            for (int i = 1; i < 51; i++)
            {
                GameObject square = GameObject.Find("Square" + i.ToString());
                square.GetComponent<SpriteRenderer>().color = new Color(Mathf.Lerp(0, 1, (listTe[i - 1] / 420F) - 0.71F), 0, 0, 1);
                Debug.Log(square.name + "   " + listTi[i-1].ToString() + "(s)   " + listVe[i-1].ToString() + "(10 m/s)   " + listTe[i-1].ToString() + "(F)   " + (Mathf.Lerp(0, 1, (listTe[0] / 420F) - 0.71F)) + "% R");
            }

            void OnMouseOver()
            {
            Debug.Log(square.name + "   " + listTi[i-1].ToString() + "(s)   " + listVe[i-1].ToString() + "(10 m/s)   " + listTe[i-1].ToString() + "(F)   " + (Mathf.Lerp(0, 1, (listTe[0] / 420F) - 0.71F)) + "% R");
            }

        }
    }

    public string stringToEdit = "Heater Dashboard";
    public string stringToEdit2 = "Expected Readings";
    public string stringToEdit3 = "Actual Readings";


    void OnGUI()
    {
        stringToEdit = GUI.TextField(new Rect(300, 10, 115, 20), stringToEdit, 25);
    stringToEdit2 = GUI.TextField(new Rect(10, 125, 120, 20), stringToEdit2, 25);
    stringToEdit3 = GUI.TextField(new Rect(10, 270, 105, 20), stringToEdit3, 25);
    }

}
1
Please use the correct tags! unityscript is or better was a JavaScript flavor like custom language used in early Unity versions and is long deprecated by now! Also just because you are using a certain IDE doesn't mean your question is about that IDE.derHugo

1 Answers

2
votes

Firstly, you created a local function OnMouseOver(), which is only available inside a Start() method.

Secondly... you created a local square variable inside a loop, thus it cannot be available beyond loop, the same thing with i, but you trying to call them both outside that for-loop.