【发布时间】:2021-05-12 15:57:48
【问题描述】:
我的主要问题是 void OnMouseOver。 Unity 不想承认名称“square”和“i”。我无法为每个游戏对象编写单独的代码,因为我有大约 50 个对象需要应用此代码。当我将鼠标悬停在一个正方形上时,我需要弹出一个特定的数字。我不确定 void OnMouseOver 是否应该在 void Start 中,但是当它在它之外时会出现更多错误。任何意见是极大的赞赏!谢谢!
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);
}
}
【问题讨论】:
-
请使用正确的标签!
unityscript是或更好的是 JavaScript 风格,类似于早期 Unity 版本中使用的自定义语言,现在早已弃用!同样,仅仅因为您使用的是某个 IDE 并不意味着您的问题与该 IDE 有关。