Search Unity

  1. Unity 6 Preview is now available. To find out what's new, have a look at our Unity 6 Preview blog post.
    Dismiss Notice
  2. Unity is excited to announce that we will be collaborating with TheXPlace for a summer game jam from June 13 - June 19. 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,580
    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