Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.

Question trying to reset value when timeline playback is finished

Discussion in 'Timeline' started by laurentlavigne, Nov 6, 2020.

  1. laurentlavigne

    laurentlavigne

    Joined:
    Aug 16, 2012
    Posts:
    6,006
    it's not doing the resetting part

    Code (CSharp):
    1. using UnityEditor.Timeline;
    2. using UnityEngine.Playables;
    3. using UnityEngine;
    4.  
    5. [ExecuteAlways]
    6. public class Shake : MonoBehaviour
    7. {
    8.     public float amplitude, speed;
    9.     Quaternion originalRotation;
    10.     public bool onTopOfAnimation;
    11.  
    12.     void OnEnable()
    13.     {
    14.         originalRotation = transform.localRotation;
    15.     }
    16.  
    17.     #if UNITY_EDITOR
    18.     bool timelineIsPlaying;
    19.     #endif
    20.  
    21.     void LateUpdate()
    22.     {
    23.         #if UNITY_EDITOR
    24.         if (Application.isPlaying == false)
    25.         {
    26.             if (timelineIsPlaying && (TimelineEditor.inspectedDirector == null || TimelineEditor.inspectedDirector?.state != PlayState.Playing))
    27.             {
    28.                 timelineIsPlaying = false;
    29.                 transform.rotation = originalRotation;
    30.             }
    31.             if (TimelineEditor.inspectedDirector?.state != PlayState.Playing)
    32.             {
    33.                 return;
    34.             }
    35.         }
    36.         #endif
    37.         if (amplitude != 0 && speed != 0)
    38.         {
    39.             if (!onTopOfAnimation)
    40.                 transform.localRotation = originalRotation;
    41.             transform.Rotate(amplitude * (.5f * Vector3.one - SmoothRandom.GetVector3(speed)));
    42.         }
    43.         else if (!onTopOfAnimation)
    44.             transform.rotation = originalRotation;
    45.     }
    46. }
     
  2. seant_unity

    seant_unity

    Unity Technologies

    Joined:
    Aug 25, 2015
    Posts:
    1,516
    Where does it set timelineIsPlaying to true?
     
    laurentlavigne likes this.
  3. laurentlavigne

    laurentlavigne

    Joined:
    Aug 16, 2012
    Posts:
    6,006
    I just added that, thanks.
    It's not working though so I'll just abandon the idea and use cinemachine.
     
    Last edited: Nov 6, 2020