So I am trying to flash a message to the player when they pickup and dropoff items, and I just want the GuiTexture to flash on the screen for a second.
Heres the code, but none of the methods I have found seem to work.
This is adapted from the code in Will Goldstones Book.
var alerttex : Texture2D ;
var deliverytex : Texture2D ;
var capacitytex : Texture2D ;
var wrongtex : Texture2D ;
static var alert : int = 0;
function Start ()
{
guiTexture.enabled = false;
alert = 0;
}
function Update () {
if (alert == 1)
{
guiTexture.texture = alerttex;
guiTexture.enabled = true;
}
else if (alert == 2)
{
guiTexture.texture = deliverytex;
guiTexture.enabled = true;
yield WaitForSeconds(0.5);
guiTexture.enabled = false;
}
else if (alert == 3)
{
guiTexture.texture = capacitytex;
guiTexture.enabled = true;
}
else if (alert == 4)
{
guiTexture.texture = wrongtex;
guiTexture.enabled = true;
}
else if (alert == 0)
{
guiTexture.enabled = false;
}
}
Right now its throwing the error the Update() cannot be a coroutine, which I am sure is because of the yield. I don’t want to destroy the game object, because I want it to happen every time if it is not correct.
The alert var is changed from another script.