im getting co routine error in my script pls help me to solve this problem.
using UnityEngine;
using System.Collections;
public class ti : MonoBehaviour {
void Start () {
}
IEnumerator Update()
{
yield return StartCoroutine(MyWaitFunction (1.0f));
animation.Play ("Barking");
print ("1");
yield return StartCoroutine(MyWaitFunction (19.0f));
animation.Play ("juming");
print ("2");
yield return StartCoroutine(MyWaitFunction (29.0f));
animation.Play ("Dancing");
Debug.Log ("abc");
}
IEnumerator MyWaitFunction (float delay) {
float timer = Time.time + delay;
while (Time.time < timer)
{
yield return null;
}
}
}
ss image added to this thread .
as the error says, you can’t make update a corutine. Anyway why are you using a corutine for an animation?
IEnumerator Update()
Make that Void
yes i want to make the animation looping every time: after all the animation running first time .then i want to make the 3animation run second time to second time .so can i want to use co-routine?
if i use void :im getting error:cannot be a iterate block .because void cannot be a iterate interface.
What is ur expected output?
i have 3 animation
barking
jumping
running
want to play animation
1st for 10sec
and 2nd for 20sec
adn 3rd for 30 sec
with the co routine process of reaping the 3 animation .
void Start () {
StartCoroutine("MyWaitFunction");
}
// Update is called once per frame
void Update () {
}
IEnumerator MyWaitFunction () {
animation.Play ("barking");
yield return new WaitForSeconds(10);
animation.Play ("jumping");
yield return new WaitForSeconds(20);
animation.Play ("running");
yield return new WaitForSeconds(30);
StartCoroutine("MyWaitFunction");
}
Ereous
December 18, 2012, 9:59am
9
Simple fix… Change Update to CoUpDate()…
in the Method if you want it to run like Update add in while(true) { //Add code that will loop }
In the Awake/Start method add StartCoroutine(CoUpdate() );