如何在单击特定对象后显示gui.button或禁用gui.button直到单击后?

时间:2014-01-21 16:40:29

标签: c# button user-interface unity3d onmousedown

到目前为止,我有这个脚本:

Using UnityEngine;
using System.Collections;

public class text : MonoBehaviour {

public GameObject mainCam; 

public bool showButton = false;



void OnGUI () {



// Make a background box
GUI.Box(new Rect(10,10,230,150), "Menu");


if (GameObject.Find("block1") && Input.GetMouseButtonDown(0)) { 

showButton = true; 

if(GUI.Button (new Rect (30,40,200,70), "Back to the blocks ")) {

print ("You clicked the button! The menu now appears");

mainCam.transform.position= new Vector3(-.13f, 0.87f, -8);

Camera.main.orthographicSize = 0.4f;



    }

} 
}
}

我希望当视图在多个块上时禁用或禁用按钮,然后当我单击一个块并且它带我到其中一个块的放大视图时,我希望gui.button出现。然后如果我带着所有块回到主视图,我想再次禁用该按钮。我不知道该怎么做。

1 个答案:

答案 0 :(得分:0)

您在编辑脚本下面的任何条件下都没有使用过showButton布尔值

   public class text : MonoBehaviour {

public GameObject mainCam; 

public bool showButton = false;



void OnGUI () {



// Make a background box
GUI.Box(new Rect(10,10,230,150), "Menu");


if (GameObject.Find("block1") && Input.GetMouseButtonDown(0)) { 

showButton = true; 

if(GUI.Button (new Rect (30,40,200,70), "Back to the blocks ") && showButton) {//check showButton
showButton = false;// when you want go back to blocks then make it false
print ("You clicked the button! The menu now appears");

mainCam.transform.position= new Vector3(-.13f, 0.87f, -8);

Camera.main.orthographicSize = 0.4f;



    }

} 
}
}