Calling a GUIText object to show or hide from a different script

Hi, here’s my problem:

I have a car running and eventually it comes out of fuel. This is controlled by a script in the car, so when this happens i want a GUIText shows an “Out of fuel” message. I’ve tried this with OnGUI but i had only problems as i’m using OnGUI for showing up a chronograph. So, i set the GUItext as disabled at the beginning of the stage (in inspector) and then i use this code:

gui_combustible = GameObject.Find ("GUI Text Combustible");
if (evento == 0) gui_combustible.SetActive(false);
else if (evento==1) gui_combustible.SetActive(true);

where the variable “evento” becomes 1 when fuel runs out.

The problem is the object GUItext never shows up. The name of this object is actually “GUI Text Combustible”.
What am i doing wrong?

You say you set the GUItext as disabled at the beginning of the stage (in inspector), is it before hitting the “Play” button to play your game ? Because in that case, you should have an error in the logs window because GameObject.Find cannot work if the game object is already deactivated.

So first check if you have an error, if not that means that there is another problem.

Good point, Kira!
That was actually the problem. I enabled it in design view and then disabled in runtime and now it works. I’m gonna test the behaviour of GUItext when i enable it in runtime and it has been already enabled in runtime to check for that error. Thank you very much.