0

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

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 出现。然后,如果我返回所有块的主视图,我希望再次禁用该按钮。我不知道该怎么做。

4

1 回答 1

0

您没有在以下任何条件下使用 showButton boolean 编辑的脚本可能对您有用

   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;



    }

} 
}
}
于 2014-01-21T17:41:05.170 回答