Search Unity

AnimationEvent problem - Solved

Discussion in 'Scripting' started by Thunder0ne, Mar 28, 2009.

  1. Thunder0ne

    Thunder0ne

    Joined:
    Mar 8, 2009
    Posts:
    23
    Solution: set normalised time of the animation to 0 on start.

    I have an AnimationEvent that is triggered for an animation only from the second time this animation is crossfaded
    Please find the code here
    Code (csharp):
    1.  
    2. function Animation2Ended{
    3.  print("debug animation 2 ended");
    4.  animation.CrossFade("idle");
    5. }
    6.  
    7. function Start () {
    8.     animation["idle"].wrapMode = WrapMode.Loop;
    9.     animation["animation1"].wrapMode = WrapMode.Once;
    10.     animation["animation2"].wrapMode = WrapMode.Once;
    11.  
    12. //Solution: set normalised time to 0.0
    13. animation["animation1"].normalizedTime = 0.0;
    14.    
    15.     var animationEvent1 = new AnimationEvent();
    16.     animationEvent1.time = animation["animation2"].clip.length * 0.5;
    17.     animationEvent1.functionName = "Animation2Ended";
    18.     animation["animation2"].clip.AddEvent(animationEvent1);
    19. }
    20.  
    21.  
    This happens only for this animation: if I use the same code with animation1 it works fine.

    What could be wrong with an animation to have an impact on AnimationEvents triggering?

    Many thanks