Hello everyone I have added a toggle button to my game scene that sends the Boolean value to a function called 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());
}
}
In another script I have a GUI box that calls the function ControlPanel () too but the result is different of the one I get when I call the same function on the Debug.Log above:
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 ());
The t2Bool and t3Bool work well but they are using the old UI method. To finalize here is the object Hydroelectric along with its function 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;
}
The values I receive in the Debug.Log are correct, but the GUI.Box does not considers the t1Bool that is being sent by the new UI method. Can you help? I hope I made myself clear.
The t1Bool Boolean is working perfectly but when I do this:
GUI.Box (new Rect (Screen.width - 310, 6, 50, 25), hydro.ControlPanel ().ToString ());
Debug.Log (hydro.ControlPanel());
ControlPanel() function returns 2 different values.