1.文本输入框
1 public string text; 2 3 void OnGUI(){ 4 text = GUI.TextField(new Rect(140, 140, 100, 40), text); 5 6 if (GUI.Button(new Rect(10, 10, 100, 50), text)) 7 { 8 print("用户单击了按钮"); 9 } 10 }
效果:
2.开关按钮控件
1 public bool toggleBool; 2 3 void OnGUI(){ 4 toggleBool = GUI.Toggle(new Rect(10, 10, 100, 30), toggleBool, "Toggle"); 5 }
效果:
3.水平滑块
1 void Update () { 2 print(hSliderValue); 3 } 4 5 private float hSliderValue=0.0F; 6 void OnGUI(){ 7 hSliderValue = GUI.HorizontalSlider(new Rect(10, 10, 100, 30), hSliderValue, 0, 10); 8 }
效果:
4.垂直滑动条,类似于水平的滑动条
时间: 2024-10-13 00:56:39