Something wrong with easy script,can someone tell me what?

I m beginner so i warn you it looks silly.Basically i want the screen to turn black after 3 seconds of loading the scene.I wrote this but it doesnt work…

#pragma strict

var Texture : Texture2D;



function OnGUI(){
        yield WaitForSeconds (3);
        GUI.DrawTexture(Rect(0, 0, Screen.width, Screen.height), Texture);
}

As far as I know OnGUI can’t be a coroutine.

Consider using the new UI tools.

BoredMormon is correct, you cannot have “yield WaitForSeconds (3);” inside the OnGUI method.

Instead, you can do something like this:

var Texture : Texture2D;
var t : float;

function Start() {
    t = Time.time + 3;
}

function OnGUI(){
    if (Time.time >= t)
        GUI.DrawTexture(Rect(0, 0, Screen.width, Screen.height), Texture);
}

Basically what I am doing is assigning “t” to be the current time plus 3.
Then I am waiting for the current time to be over t (which will be 3 seconds later) then I draw that texture.

hey thx for the code,worked perfectly!

Glad it helped :slight_smile: