0

So far I have this script:

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;



    }

} 
}
}

I want the button to be disabled or inactive when the view is on multiple blocks, then when I click on one block and it takes me to a zoomed in view of one of the blocks, I want the gui.button to appear. Then if I go back to the main view with all the blocks, I want the button disabled again. I'm not sure how to do that.

Kala J
  • 2,040
  • 4
  • 45
  • 85

1 Answers1

0

You haven't used showButton boolean in any of your conditions below edited script may work for you

   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;



    }

} 
}
}
Dasu
  • 433
  • 6
  • 16
  • For some reason, it just disables everything. Even if I check it active or inactive, the checkbox of showButton doesn't work :/ It's weird. – Kala J Jan 21 '14 at 22:04
  • Actually, an interesting thing to note is: The mainCam is always set at a specific coordinate, so what I did was: void Update() { if (mainCam.transform.position == new Vector3(0, 1.1f, -8)) { GUI.enabled = false; } } and this view would only be for when the main Camera is positioned at a certain location, which logically should work but the GUI for some reason, is not disabled. – Kala J Jan 21 '14 at 22:27