Search Unity

  1. Unity support for visionOS is now available. Learn more in our blog post.
    Dismiss Notice

Please, I Need Animation Key Binding Help

Discussion in 'Animation' started by Tahrgat, May 5, 2014.

  1. Tahrgat

    Tahrgat

    Joined:
    May 5, 2014
    Posts:
    1
    Okay, I am new and having trouble with java script. Sorry if I am bugging anyone with this question. I know this is probably simple, but I have been trying to figure this out for days. I made a walking animation for a sword where it sways up and down a bit. I tried binding it to the "w" key but the animation just keeps playing no matter what I do. here is the code I obtained to try this.

    function Update()
    {
    if(Input.GetKeyDown("w"))
    {
    // Plays the walksw animation - stops all other animations
    animation.Play("walksw", PlayMode.StopAll);
    }
    }

    Please tell me clearly and simply, for a very new noob, how to make this work the way I want. A lot of people hint at things, but I can't find a place that will spell it out for me. How do I correct this code so that the sword will only do the walk animation when I click "w" on the keyboard. the animation is named walksw btw. Thank you for reading. Please help me to stop tearing my hair out in frustration.
     
  2. Melang

    Melang

    Joined:
    Mar 30, 2014
    Posts:
    166
    It should work, you probably have WrapMode.Loop on the clip - set it to Default or Once instead. And check that you don't have it set as default animation with Play Automatically on in the inspector.