I want to live a GameObject for some seconds before destroy it.I saw the code by c# like this in documentation:
IEnumerator Awake() {
print(Time.time);
yield return new WaitForSeconds(5);
print(Time.time);
}
how to use this code?
If I put it in my code like this:
void update(){
…
Awake();
…
}
It is not called.Noting happen!
If I put it like this
void update(){
…
yield return new WaitForSeconds(5);
…
}
There is a error like this :
error CS1624: The body of demo.Update()' cannot be an iterator block because
void’ is not an iterator interface type
If I put it like this:
void update(){
…
yield new WaitForSeconds(5);
…
}
There is a red line .
How to use this WaitForSeconds?Thanks!