x


About WaitForSeconds

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 becausevoid' 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!

more ▼

asked Aug 03 '11 at 06:26 AM

noob22 gravatar image

noob22
48 42 47 49

(comments are locked)
10|3000 characters needed characters left

1 answer: sort voted first

Or just:

Destroy(theGameObject,5);
more ▼

answered Aug 03 '11 at 06:28 AM

Waz gravatar image

Waz
6.5k 22 33 71

If I want to play an animation after that,how to do ?

Aug 03 '11 at 06:35 AM noob22

You could queue the animation to start in 5 seconds. In Javascript, yield is actually really easy too:

function DieSoonThenExplode()
{
    yield WaitForSeconds(5);
    otherObject.animation.Play("explosion");
    Destroy(gameObject);
}

The C# isn't much difference, but if you're struggling with it, I'd suggest using Javascript.

Aug 03 '11 at 06:38 AM Waz

I want to know the difference between c# and Js.Because I dont know where the function I should put.When I put it in update(),it dont work like having not be called.

Aug 03 '11 at 06:53 AM noob22

StartCoroutine(Awake());It is called like this!

Aug 03 '11 at 07:23 AM noob22
(comments are locked)
10|3000 characters needed characters left
Your answer
toggle preview:

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this question

By Email:

Once you sign in you will be able to subscribe for any updates here

By RSS:

Answers

Answers and Comments

Topics:

x4179
x539
x170
x4

asked: Aug 03 '11 at 06:26 AM

Seen: 1480 times

Last Updated: Aug 03 '11 at 07:23 AM