2016-01-06 37 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);