Search Unity

Can animations from the Animation component run in the scene view?

Discussion in 'Animation' started by FeastSC2, Sep 8, 2017.

  1. FeastSC2

    FeastSC2

    Joined:
    Sep 30, 2016
    Posts:
    978
    I do some simple animations on rocks just to give them a bit of movement in my game. Is it possible to simulate the animations without being in play mode? (not with Mecanim)

    Here's what I got but it doesn't simulate in the scene view

    Code (CSharp):
    1. [ExecuteInEditMode]
    2. public class AnimationHelp : MonoBehaviour
    3. {
    4.     public float Delay = 0f;
    5.     private float DelayTimer;
    6.  
    7.     public float AnimScale;
    8.  
    9.     public float Speed = 1f;
    10.  
    11.     [Range(0,1)] public float PrewarmPercent = 0f;
    12.  
    13.     private Animation Animation;
    14.     void Start ()
    15.     {
    16.         Animation = GetComponent<Animation>();
    17.         DelayTimer = Delay;
    18.         Animation.playAutomatically = false;
    19.         transform.localPosition = Vector3.zero;
    20.         transform.localEulerAngles = Vector3.zero;
    21.         transform.localScale = Vector3.one;
    22.     }
    23.  
    24.     void Update ()
    25.     {
    26.         Debug.Log("DelayTimer: " + DelayTimer);
    27.  
    28.         if (Animation.isPlaying) return;
    29.  
    30.         DelayTimer -= Time.deltaTime;
    31.  
    32.         if (DelayTimer < 0)
    33.         {
    34.             var animState = Animation.CrossFadeQueued(Animation.clip.name);
    35.             animState.normalizedSpeed = Speed;
    36.             animState.normalizedTime = PrewarmPercent;
    37.         }
    38.     }
    39. }
     
  2. Mecanim-Dev

    Mecanim-Dev

    Joined:
    Nov 26, 2012
    Posts:
    1,675
    FeastSC2 likes this.