x


Animation Wait C#

I'm trying to get an animation to start only after a certain amount of time has passed.

using UnityEngine;
using System.Collections;

public class CannonFire : MonoBehaviour
{
    bool playAnim = true;
    void Start(){

    }

    void Update(){
       if(playAnim){
         Wait();       
       }
    }

    IEnumerator Wait(){
       playAnim = false;
       yield return new WaitForSeconds(5);
       animation.Play();
    }
}
more ▼

asked Jan 07 '12 at 03:39 PM

davelupt gravatar image

davelupt
16 1 1 2

And are we supposed to look into our magic eight-balls in order to determine the problem, Willis?

Jan 07 '12 at 03:45 PM OrangeLightning
(comments are locked)
10|3000 characters needed characters left

2 answers: sort voted first
using UnityEngine;
using System.Collections;

public class CannonFire : MonoBehaviour
   {

 public  bool playAnim ;

 public Animation move;

void Start(){

          playAnim = true;
            }

void Update(){

   if(playAnim){

   playAnim = false;
   StartCoroutine(Wait());

               }
                 }//update ends

   public  IEnumerator Wait(){

   yield return new WaitForSeconds(5);
   move.Play("run");
          }
 }

animationc#waitforseconds

more ▼

answered Jan 07 '12 at 03:55 PM

robert_mathew gravatar image

robert_mathew
522 27 36 44

use StartCoroutine(Wait()); instead of Wait(); if any clarification you can ask me if this is the appropriate answer for your questions don not forget to up vote this answer

Jan 07 '12 at 03:58 PM robert_mathew
(comments are locked)
10|3000 characters needed characters left

You need to call StartCoroutine with your Wait function rather than just call Wait. More information at http://unity3d.com/support/documentation/ScriptReference/MonoBehaviour.StartCoroutine.html. Also please be sure to include more information about your issues in the future.

more ▼

answered Jan 07 '12 at 03:50 PM

mpavlinsky gravatar image

mpavlinsky
581 4 5 11

(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:

x4165
x3792
x170

asked: Jan 07 '12 at 03:39 PM

Seen: 1705 times

Last Updated: Jan 07 '12 at 03:58 PM