x


Show/hide GUI texture

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?

more ▼

asked Jan 08 '12 at 02:46 PM

Pixelen gravatar image

Pixelen
63 6 6 8

(comments are locked)
10|3000 characters needed characters left

2 answers: sort newest

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.

more ▼

answered Jan 08 '12 at 11:16 PM

aldonaletto gravatar image

aldonaletto
41.6k 16 42 197

Thank you! This worked perfectly.

Jan 09 '12 at 07:30 AM Pixelen
(comments are locked)
10|3000 characters needed characters left

Use something like this:

var showButton = false;

function OnMouseDown() {
     var button = gameObject.Find("EasyButton");

     if (showButton) {
        button.active = true;  
     }
}
more ▼

answered Jan 08 '12 at 10:39 PM

tatelax gravatar image

tatelax
131 11 20 23

(comments are locked)
10|3000 characters needed characters left
Your answer
toggle preview:

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this question

By Email:

Once you sign in you will be able to subscribe for any updates here

By RSS:

Answers

Answers and Comments

Topics:

x478
x116
x78
x36

asked: Jan 08 '12 at 02:46 PM

Seen: 3406 times

Last Updated: Jan 09 '12 at 07:30 AM