Search Unity

Scripting sequenzes of animation clips

Discussion in 'Scripting' started by thpetsen, Sep 27, 2010.

  1. thpetsen

    thpetsen

    Joined:
    Feb 25, 2010
    Posts:
    21
    Hi,
    I have a GameObject with an Animation component containing a number of different animations.

    What I want to do is create different sequenzes of these animations and trigger an event (callback or signal) when the sequenze has animated (or if the sequenze has been interrupted - player actions can trigger an animation change).

    example:
    Code (csharp):
    1.  
    2. void Awake()
    3. {
    4.     // ...
    5.    foreach (AnimationState anim in animation) {
    6.        anim.wrapMode = WrapMode.Once;
    7.        anim.speed = Speed;
    8.        anim.normalizedSpeed = anim.normalizedSpeed/Time.timeScale;
    9.    }
    10.    do_idle1()
    11. }
    12.  
    13. void do_idle1()
    14. {
    15.   string[] sq = new string[] { "clip20", "clip19", "clip12" , "clip20" };
    16.  
    17.   foreach(string clip in sq) {
    18.      animation.CrossFadeQueued(clip, 0.3f,QueueMode.CompleteOthers);  
    19.   }
    20. }
    I have a few questions here:
    1) Is there a simple way to tell when the last clip has finished playing (clip20, not the first instance, but the last) ?
    2) Seems that CrossFadeQueued only uses correct speed on the first clip and not the rest, any way around this ?
    (we are using a variable-speed physics-simulation where we modify Time.timeScale, but unfortunately this effects the animations as well).

    Currently I'm using a setup where an AnimatinEvent at the end of each clip triggers the next clip in sequenze, but for some strange reason it seems that only animation.Play() is guaranteeing that these are actually triggered (CrossFade don't), but the main problem with Play() is that it does not CrossFade.

    To summarize:
    What we would like to to is:
    a) set the same timescale for all the animation clips.
    b) animate the whole sequenze of clips.
    c) know exactly when the last clip in the sequenze has finished animatng.

    Any hints or ideas are very welcome !

    Cheers
    /Thomas
    p.s. we are running Pro version of Unity 2.6