Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. We have updated the language to the Editor Terms based on feedback from our employees and community. Learn more.
    Dismiss Notice

Animation Scripting Problem! HELP!

Discussion in 'Animation' started by Deshalsky, Dec 29, 2013.

  1. Deshalsky

    Deshalsky

    Joined:
    Nov 16, 2013
    Posts:
    57
    Hi there!
    I'm not so good at scripting so I got some problems..

    I have put 3 animations on a GameObject;
    Idle
    Walk
    Sprint

    I want the "Idle" animation to play whenever I go into PlayMode.
    I want the "Walk" animation to play when I press "W,S,D,A" on my keybord
    I want the "Sprint" animation to play when I press "Left Shift" on my keybord

    My "Idle" animation works fine...Except it never stops, Even if I play a new animation.
    When I press "W,S,D,A" nothing happens.
    And the same thing with my "Left Shift".

    I have made a script that should work:

    #pragma strict

    function Start ()
    {

    }

    function Update ()
    {

    //Button Down

    if (Input.GetButtonDown("Horizontal") || Input.GetButtonDown("Vertical"))
    {
    animation.Play("Walk", PlayMode.StopAll);
    animation.Stop("Idle");
    }

    if (PlayMode)
    {
    animation.Play("Idle");
    }

    if (Input.GetButtonDown("Sprint"))
    {
    animation.Play("Sprint");
    }

    //Button Up

    if (Input.GetButtonUp("Horizontal") || Input.GetButtonUp("Vertical"))
    {
    animation.Stop("Walk");
    animation.Play("Idle");
    }

    if (Input.GetButtonUp("Sprint"))
    {
    animation.Stop("Sprint");
    }
    }

    Can anybody help me out?
    Thanks for your help!
     
  2. Deshalsky

    Deshalsky

    Joined:
    Nov 16, 2013
    Posts:
    57