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);
}
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.