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.
  2. We have updated the language to the Editor Terms based on feedback from our employees and community. Learn more.
    Dismiss Notice

Question Animation Event How to Set time in Custom Editor?

Discussion in 'Animation' started by Aillenia, Nov 5, 2020.

  1. Aillenia

    Aillenia

    Joined:
    Feb 7, 2018
    Posts:
    3
    Code (CSharp):
    1. private void SetAnimationEvent(float time)
    2.         {
    3.             var prevEvents = AnimationUtility.GetAnimationEvents(m_selectAnimClip).ToList();
    4.          
    5.             var animEvent = new AnimationEvent();
    6.             animEvent.time = time;
    7.             prevEvents.Add(animEvent);
    8.             var newEventsArr = prevEvents.ToArray();
    9.          
    10.          
    11.             AnimationUtility.SetAnimationEvents(m_selectAnimClip, newEventsArr);
    12.         }

    this code in Editor,
    but event time of select Animation Clip in Event is be set up in a strange time
    animTime.png (Time set from the left : 0s, 0.01s, 0.5s, 1s, 1.02s, 1.1s)

    How do I set the time?
     
    Last edited: Nov 5, 2020
  2. Kybernetik

    Kybernetik

    Joined:
    Jan 3, 2013
    Posts:
    2,497
    animEvent.time = m_time;

    Did you mean to use the time parameter?
     
  3. Aillenia

    Aillenia

    Joined:
    Feb 7, 2018
    Posts:
    3
    m_time is wrong code, this mean time Parameter same