Hi, I’ve got a problem with showing and hiding GUI textures. When I click a button I want it to hide and a different one to show. On the original button I have this code:
function OnMouseDown() {
gameObject.active=false;
gameObject.Find("EasyButton").SendMessage("Show");
}
And on the other button I have this code:
function Show() {
gameObject.active=true;
}
Can anyone tell me where I’m going wrong?
You can’t find an inactive object with Find, and even if you could, I suspect that it would not answer to SendMessage.
If you’re using GUITexture, disable/enable the textures with guiTexture.enabled instead:
function OnMouseDown() {
guiTexture = false; // or use "gameObject.active=false;" as before
gameObject.Find("EasyButton").guiTexture.enabled = true;
}
You don’t need the other button’s script in this case.
Use something like this:
var showButton = false;
function OnMouseDown() {
var button = gameObject.Find("EasyButton");
if (showButton) {
button.active = true;
}
}