Search Unity

Crossfading Query

Discussion in 'Scripting' started by Superflat, May 19, 2009.

  1. Superflat

    Superflat

    Joined:
    Mar 19, 2009
    Posts:
    354
    Hi,

    I got a model in unity with 3 animations. I attached an image of what the model looks like.

    What i'm trying to do is quite obvious, but i'm having some trouble with crossfade looking good when i hit play. I'm assuming it's something to do with my script but i'm not entirely sure where it goes off the deep end. It doesn't appear to be doing the crossfading properly. Having read other posts, people suggest i call the CrossFade from the onUpdate function but how would that work with my buttons?

    Any insight would be welcome.


    Code (csharp):
    1. var logo : Texture2D;
    2.  
    3. function OnGUI() {
    4.     GUI.Label(Rect(0, 0, 65, 188), logo);
    5.    
    6.     GUI.Box(Rect(50,10,100,120), "Animatie Menu");
    7.    
    8.     if(GUI.Button(Rect(20,40,80,20), "Animatie 1"))
    9.     {
    10.         if(animation.IsPlaying("animation2") || animation.IsPlaying("animation3") )
    11.         {
    12.             animation.CrossFade("animation1");
    13.         } else {
    14.             animation.Play("animation1");
    15.         }
    16.     }
    17.     if(GUI.Button(Rect(20,70,80,20), "Animatie 2"))
    18.     {
    19.         if(animation.IsPlaying("animation1") || animation.IsPlaying("animation3") )
    20.         {
    21.             animation.CrossFade("animation2");
    22.         } else {
    23.             animation.Play("animation2");
    24.         }
    25.     }
    26.     if(GUI.Button(Rect(20,100,80,20), "Animatie 3"))
    27.     {
    28.         if(animation.IsPlaying("animation1") || animation.IsPlaying("animation2") )
    29.         {
    30.             animation.CrossFade("animation3");
    31.         } else {
    32.             animation.Play("animation3");
    33.         }
    34.     }
    35. }
    36.  
    37. @script ExecuteInEditMode()
     

    Attached Files:

  2. Superflat

    Superflat

    Joined:
    Mar 19, 2009
    Posts:
    354
  3. runevision

    runevision

    Joined:
    Nov 28, 2007
    Posts:
    1,892
    It looks like not all your animations have animation curves for all the bone rotations you are animating. Could that be the problem? Try to look in your program you used to make the animations and ensure that all the animatable rotations have animation curves in all the animations.

    Rune
     
  4. ihatsu

    ihatsu

    Joined:
    Mar 14, 2009
    Posts:
    30