- Home /
How can i stop animation clip from being playing ?
I'm using Animator to play the animation clip. I created two states. Animation_Sign and Animation_Idle.
The problem is in the script the switching between the cameras is working but the part to stop the animation clip is not working.
 using System.Collections;
 using System.Collections.Generic;
 using UnityEngine;
 
 public class AnimationCamera : MonoBehaviour
 {
     public Camera animationCamera;
     public Camera mainCamera;
     Animator _anim;
 
     private void Start()
     {
         animationCamera.enabled = false;
         mainCamera.enabled = true;
         _anim = GetComponent<Animator>();
     }
 
     private void Update()
     {
         if (Input.GetKeyDown(KeyCode.C))
         {
             animationCamera.enabled = !animationCamera.enabled;
             mainCamera.enabled = !mainCamera.enabled;
 
             if (animationCamera == true)
             {
                 _anim.CrossFade("Animation_Sign", 0);
             }
             else
             {
                 _anim.CrossFade("Animation_Idle", 0);
             }
         }
     }
 }
 
I used a break point each time it's getting to the line:
 if (animationCamera == true)
animationCamera is true. It's never false.
What i want to do is when i switch to the animationCamera it will start playing the animation clip "Animation_Sign" and when i switch to the main camera stop the animation playing. and then again when switching start playing switching stop and so on.
Answer by SohailBukhari · May 08, 2017 at 07:14 AM
you are checking animationCamera == true and it always return true because its component not bool so you need to check animationCamera.enabled and take decision, replace your update with the following code.
 if (Input.GetKeyDown(KeyCode.C))
         {
             animationCamera.enabled = !animationCamera.enabled;
             mainCamera.enabled = !mainCamera.enabled;
 
             if (animationCamera.enabled)
             {
                  _anim.CrossFade("Animation_Sign", 0);
             }
             else
             {
                  _anim.CrossFade("Animation_Idle", 0);
             }
         }
this will solve your problem.
Your answer
 
 
              koobas.hobune.stream
koobas.hobune.stream 
                       
                
                       
			     
			 
                