大家好我已经在游戏场景中添加了一个切换按钮,将布尔值发送给名为turbine1的函数:
using UnityEngine;
using System.Collections;
using Assets.Code.PowerPlants;
public class hydroProwerControlPanel : MonoBehaviour {
private HydroElectric hydro;
public hydroProwerControlPanel (){
hydro = new HydroElectric();
}
public void turbine1State (bool t1) {
hydro.t1Bool = t1;
Debug.Log (t1);
Debug.Log (hydro.ControlPanel());
}
}
在另一个脚本中,我有一个GUI框,它调用函数ControlPanel(),但结果与我在上面的Debug.Log上调用相同函数时获得的结果不同:
hydro.t2Bool = GUI.Toggle (new Rect (25, 195, 100, 50), hydro.t2Bool, "Turbina 1 MW");
hydro.t3Bool = GUI.Toggle (new Rect (25, 235, 100, 50), hydro.t3Bool, "Turbina 0.5 MW");
GUI.Box (new Rect (Screen.width - 310, 6, 50, 25), hydro.ControlPanel ().ToString ());
t2Bool和t3Bool运行良好,但他们使用旧的UI方法。 最后确定的是Hydroelectric对象及其功能ControlPanel:
public HydroElectric ()
{
t1Bool = true;
t2Bool = true;
t3Bool = false;
prod = 0f;
}
public float ControlPanel ()
{
turbina1 = t1Bool ? 1.5F : 0;
turbina2 = t2Bool ? 1 : 0;
turbina3 = t3Bool ? 0.5F : 0;
prod = turbina1 + turbina2 + turbina3;
return prod;
}
我在Debug.Log中收到的值是正确的,但GUI.Box不考虑新UI方法发送的t1Bool。你能帮我吗?我希望我能说清楚。
t1Bool布尔工作正常,但是当我这样做时:
GUI.Box (new Rect (Screen.width - 310, 6, 50, 25), hydro.ControlPanel ().ToString ());
Debug.Log (hydro.ControlPanel());
ControlPanel()函数返回2个不同的值。