Search Unity

  1. Engage, network and learn at Unite Austin 2017, Oct 3 - 5. Get your ticket today!
    Dismiss Notice
  2. Introducing the Unity Essentials Packs! Find out more.
    Dismiss Notice
  3. Check out all the fixes for 5.6 on the patch releases page.
    Dismiss Notice
  4. Unity 2017.1 is now released.
    Dismiss Notice
  5. Help us improve the editor usability and artist workflows. Join our discussion to provide your feedback.
    Dismiss Notice
  6. Unity 2017.2 beta is now available for download.
    Dismiss Notice

2 Animations at once

Discussion in 'Scripting' started by Duskling, Feb 1, 2012.

  1. Duskling

    Duskling

    Joined:
    Mar 15, 2011
    Posts:
    1,197
    I read about animation mixing, but that didn't work for me.

    Code (csharp):
    1.  
    2. function Animations()
    3. {
    4.     if(weaponsController.gunScript)
    5.     {
    6.         animation.AddClip(weaponsController.gunScript.weaponIdleAnim, "weaponIdleAnim");
    7.         animation.Blend("weaponIdleAnim");
    8.     }
    9.    
    10.     // Running
    11.     if(Input.GetAxis("Vertical") > .1  controller.isGrounded)
    12.     {
    13.         animation.CrossFade("run", 0.3);
    14.     }
    15.    
    16.     else if(Input.GetAxis("Vertical") < -.1  controller.isGrounded)
    17.     {
    18.         animation.CrossFade("back", 0.3);
    19.     }
    20.    
    21.     else
    22.     {
    23.         if(Input.GetAxis("Horizontal")  !Input.GetAxis("Vertical")  controller.isGrounded)
    24.         {
    25.             animation.CrossFade("turn",0.3);
    26.         }
    27.         else if (controller.isGrounded)
    28.         {
    29.             animation.CrossFade("idle", 0.1);
    30.         }  
    31.         else
    32.         {
    33.             animation.CrossFade("jump", 0.3);
    34.         }  
    35.     }
    36. }
    37.  
    Everything is working fine, but I just want "weaponIdleAnimation" to play correctly while you are running, jumping etc. weaponIdleAnimation is being added, but trying to animate it either overrides all the other animations or doesn't play at all.
     
    Last edited: Feb 1, 2012