2016-01-06 57 views
0

大家好我有一个酒吧,在那里我显示由用户输入改变一个变量,它是在OnGUI()这个脚本:GUI框的值没有更新

public class StateManager : MonoBehaviour 
{ 
    public Vector2 pos1 = new Vector2(10,200); 
    public Vector2 size = new Vector2(60,20); 
    private HydroElectric ec; 
    public Texture2D emptyProd; 
    public Texture2D fullProd; 

    public StateManager() 
    { 
     ec = new HydroElectric(); 
    } 

    void OnGUI() 
    { 
     float tt; 
     tt = (ec.HydroControlPanel()/6); 

     GUI.BeginGroup (new Rect (pos1.x, pos1.y, size.x, size.y)); 
     GUI.Box (new Rect (0, 0, size.x, size.y), emptyProd,GUIStyle.none); 
     GUI.BeginGroup (new Rect (0, 0, size.x *tt , size.y)); 
     GUI.Box (new Rect (0, 0, size.x, size.y), fullProd, GUIStyle.none); 
     GUI.EndGroup(); 
     GUI.EndGroup(); 

    } 
} 

这个变量可以从0°去6,所以我把它分成0到1的比例来揭示吧。我用点sintax调用价值来自这里:

Public void ShowIt() 
     { 
      ec.t1Bool = GUI.Toggle (new Rect (25, 55, 100, 50), ec.t1Bool, "Turbina 2 MW"); 

      ec.t2Bool = GUI.Toggle (new Rect (25, 95, 100, 50), ec.t2Bool, "Turbina 3 MW"); 

      ec.t3Bool = GUI.Toggle (new Rect (25, 135, 100, 50), ec.t3Bool, "Turbina 1 MW"); 

      GUI.Box (new Rect (Screen.width - 100, 60, 80, 25), ec.HydroControlPanel().ToString());  // PRODUCED ENERGY 

     } 

如何:

public float HydroControlPanel() 
     { 
      turbina1 = t1Bool ? 2 : 0; 
      turbina2 = t2Bool ? 3 : 0; 
      turbina3 = t3Bool ? 1 : 0; 

      prod = turbina1 + turbina2 + turbina3; 
      return prod; 
     } 

的BOOLS正在使用的是其他脚本,因为工作的切换按钮,我有这个值显示,类似这样的变化我可以让我的酒吧更新?它开始显示默认值,但从未改变。

回答

1

的问题是在这条线

tt = (ec.HydroControlPanel()/6); 

你将通过浮动整数,因此结果将始终是整数。你应该用浮点除法:

tt = (ec.HydroControlPanel()/6f);