Gui question

Hi, Im trying to emulate the fade in script in a way I can comprehend. This kinda explains my intent:

var gui : GUITexture;
gui.enabled=false;
function Update () {
	 if (Input.GetKeyDown("b")) {
	 	gui.enabled=true;
	 }
	 if (Input.GetKeyUp("b")) {
	 yield;
	 	 yield;
	 	 	 yield;
	 	 	 	 yield;
	 	 	 	 	 yield;
	 	 	 	 	 	 yield;
	 	 	 	 	 	 	 yield;
	 	 	 	 	 	 	 	 yield;
	 	 	 	 	 	 	 	 	 yield;
	 	 	 	 	 	 	 	 	 	 yield;
	 	 	 	 	 	 	 	 	 	 	 yield;
	 	 	 	 	 	 	 	 	 	 	 	 yield;
	 	 	 	 	 	 	 	 	 	 	 	 	 yield;
	 	 	 	 	 	 	 	 	 	 	 	 	 	 yield;
	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 yield;
	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 yield;
	gui.enabled=false;
}
}

Yeah I know its scruffy. The point is Im getting errors using the Fadein script from the wiki. Probably because my manager GO has the same script on it, 4 times, referencing 4 gui’s with different input keys assigned. The error is that unity cannot find the varible colour with the wiki fade in.

The error with my script above is that update cant be a coroutine. But without all those yields, the gui dissappears too quickly.
Could someone help me figure this out? Maybe a generic example or two of a co-routine so I can try and understand those?
Cheers y’all
AC

Is the GUI element GUI Text that the Fade-In is giving the error? I remember having this problem a while ago after one of the version upgrades. If you still don’t have an answer when I get home I will look up the fix. It was actually easy if you know what needs to be done. The hard part was figuring out what needs to be done. It might be that you need to grab the material first.

Also, I don’t quit understand the comment about the same 4 scripts on a single GO. Do you meant that you ahve 4 FadeIn scripts on the same GO? If so, that probably won’t work. Place a single FadeIn on each Gui object GO, or modify the script with a var at the top where you can drag the GUI object to it in the inspector and use that variable instead to change the color on.

If you want to use your yields, move them into another function besides Update() and call that function from Update(). You will probably only want to call it once though.

While Update itself cannot be a coroutine, functions it calls can:

function Update () {

  Foo();

}

function Foo () {

  doSomethingHere();
  yield WaitForSeconds(1);
  doSomethingElse();

}

So you might try moving the fade in/out and coroutine code into another function instead of leaving it in your Update loop. Sorry, I haven’t personally checked the Wiki’s fade in/out script as I sort of knocked out my own as an experiment to learn the general techniques needed.

Thanks guys!
Hey Tom, as simple as that looks in retrospect, thats exactly what I needed to know. Cheers
AC

Just thought I’d share this little breakthrough with other scriptnoobs out there:

var gui : GUITexture;
gui.enabled=false;
function Update () {
	 if (Input.GetKeyDown("h")) {
	 	Display();
}
 if (Input.GetKeyUp("h")) {
 	Hide();
 }
}
function Display(){
	 	gui.enabled=true;
	 }
function Hide(){
	yield WaitForSeconds(4);
	
	gui.enabled=false;
}

It works but is hardcoded to h. Easy to fix I’m sure so it exposes the option in the inspector but I settled for this just to get it rolling…Thanks guys
AC

var key : String;

//...
Input.GetKeyDown(key);

PS: Don’t know if the "key : String; cast is ok in JS, but you get the idea. :wink:

-Jeremy

Premo. I had a hunch it might be string. Strings and arrays are words that I couldnt figure out for a long time.
Thanks Jeremy
AC

heh, np.

-Jeremy