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

Animations scripting problem! Help!

Discussion in 'General Discussion' 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
  3. Deshalsky

    Deshalsky

    Joined:
    Nov 16, 2013
    Posts:
    57
  4. gryff

    gryff

    Joined:
    Apr 17, 2012
    Posts:
    360
    Not quite sure this is the best forum to be asking for help - Animation, Scripting or Support are probably where you should be asking.

    That said, your script has a variable "Playmode" which I assume is a boolean and is True for the idle situation. If you start with figure idling then unless you set Playmode to False somewhere it is (re)starting that animation every update. You need to rethink how you start the idle animation.

    cheers, gryff :)
     
  5. UnknownProfile

    UnknownProfile

    Joined:
    Jan 17, 2009
    Posts:
    2,311
    Stop bumping. We see it. Saying "HELP" once every few minutes will get you nowhere. A good rule of thumb is once a day for bumping. Also, you posted in the wrong section. Gossip is for just that: gossip (not help). Post in in the programming section. On one last note, code tags would make your post readable with the code nicely contained rather than in a mess in the middle of the screen.
     
  6. Deshalsky

    Deshalsky

    Joined:
    Nov 16, 2013
    Posts:
    57
    But how can i do it? I want the Idle animation to play all time (Just not when another animation is playing). Is there another way to script so it plays constantly?
     
  7. Deshalsky

    Deshalsky

    Joined:
    Nov 16, 2013
    Posts:
    57
    Sorry :/
    I gonna think of that next time!