Search Unity

Add animations to 2D Gameplay Tutorial

Discussion in 'Scripting' started by DiegoC, May 1, 2011.

  1. DiegoC

    DiegoC

    Joined:
    Jan 14, 2011
    Posts:
    36
    Hi,
    I am look the 2D Gameplay Tutorial (unity3d.com/support/resources/tutorials/2d-gameplay-tutorial), but i want to add 2 animations (kick ,attack), when I push Fire3 and Fire1.
    I want that when I give a push to the key Fire3 or Fire1. the animation to automatic play and when finished to play enable idle.
    Any idea, please?

    Here the code with Fire3 only :
    Code (csharp):
    1. function Update () {
    2. var controller : PlatformerController = GetComponent(PlatformerController);
    3.  
    4. // We are not falling off the edge right now
    5. if (controller.GetHangTime() < hangTimeUntilFallingAnimation) {
    6. // Are we moving the character?
    7. if (controller.IsMoving())
    8. {
    9. if (Input.GetButton ("Fire2"))
    10. animation.CrossFade ("run");
    11. else
    12. animation.CrossFade ("walk");
    13. }
    14. // Go back to idle when not moving
    15. else
    16. if (Input.GetButton ("Fire3"))
    17. animation.CrossFade ("kick");
    18. else
    19. animation.CrossFade ("idle", 0.5);
    20. }
    21. --------------------------------------------------------------------------------
    22.