- Home /
How to make a character move for some time and stand for some time?
I want my character to stand for some time and walk for some time depending on flag value, using corouitine. However it doesn't work properly since corutine is not working and v value changes every frame
IEnumerator Walking() {
         v = 0.2f;
         anim.SetFloat("Walk", v);
         yield return new WaitForSeconds(5f);
     }
     IEnumerator Standing()
     {
 
       
         yield return new WaitForSeconds(7f);
         v = 0;
         anim.SetFloat("Walk", v);
         yield break;
     }
 
 
     // Use this for initialization
     void Start()
     {
         anim = GetComponent<Animator>();
         anim.speed = anim.speed * 0.5f;
         v = 0.2f;
        anim.SetFloat("Walk", v);
     }
 
     // Update is called once per frame
     void Update()
     {
 bool IsStanding = RandomBool();
         if (IsStanding == true)
         {
             StartCoroutine("Standing");
         }
         else
         {
             v = 0.2f;
             anim.SetFloat("Walk", v);
 
         }
 
 
 
 
 
     }
  bool RandomBool ()
 {
     if (Random.value >= 0.5)
     {
         return true;
     }
     return false;
 }
 
Answer by hectorux · Nov 05, 2018 at 08:28 PM
I think you need to make loops, in your first coroutine you just yield when you have finished it, you doesn't even need the yield break of the sceond oe
I think my biggest problem was that i was trying to start coroutine in the update function. Thanks, however!
Your answer
 
 
             Follow this Question
Related Questions
Why do I get the warning: The AnimationClip 'idle_04' used by the Animation component 0 Answers
Imported Blender Animations not Working 1 Answer
Can animation clips be swapped out of the animator override controller in runtime? 1 Answer
How to re-order transitions in animator controller. 0 Answers
Coroutines and animation triggers 1 Answer
 koobas.hobune.stream
koobas.hobune.stream 
                       
                
                       
			     
			 
                