I’m trying to have a timer after a message pops up in a label so after 3 seconds it becomes a blank label. But when I use the code below i get the error:
Assets/GameGrass/SHOWMESSAGE.cs(8,6): error CS1624: The body of SHOWMESSAGE.Update()' cannot be an iterator block because void’ is not an iterator interface type
any help? :S
public class SHOWMESSAGE : MonoBehaviour {
private string message = "";
void Update()
{
if (Input.GetKeyDown("h")) // You must use 'Input' only at the 'Update' functions
{
if(variablesResources.GetWood() >= 3)
{
message = "YOU BUILT A HOUSE";
variablesResources.SetWood(-3);
yield return new WaitForSeconds(5);
message = "";
}
else
{
message = "YOU DONT HAVE ENOUGH WOOD";
}
}
}
void OnGUI() // Is not static and you should not be making it so
{
GUI.Label(new Rect(50, 50, 300, 20), message);
}
@Nidre - it's an answer - make it an answer not a comment :)
– whydoidoitmy bad :) Wrong button :)
– Nidre