Search Unity

  1. Megacity Metro Demo now available. Download now.
    Dismiss Notice
  2. Unity support for visionOS is now available. Learn more in our blog post.
    Dismiss Notice

Can't get animations to work.

Discussion in 'Editor & General Support' started by RPMonkey, Sep 18, 2014.

  1. RPMonkey

    RPMonkey

    Joined:
    Sep 18, 2014
    Posts:
    1
    Hi, i have been trying to get this simple animation script to work. I out the script into my first person controller but when i press 'w' nothing happens.I have made my animations using Unity's animation window and the script references my animation file (file name being 'walk'). Can someone please tell what i am doing wrong?

    function Update() {
    if(Input.GetKeyDown("w")) {

    animation.Play("walk");
    }
    }
     
  2. N1warhead

    N1warhead

    Joined:
    Mar 12, 2014
    Posts:
    3,884
    I'm starting to notice that more people actually come hear to find help than actually answer questions.
    So I'll try my best to help you sense nobody else has yet. Or they aren't answering because it's all over the net to find why this isn't working lol.

    But I believe what you should be doing is, once you make your animation, lets just say you want a box to move (no First person controller) to make things easier.

    A couple things need to be done..

    A good place to learn BASIC and I use basic as the keyword here BASIC animation learning is to make sure it is a Legacy Animation as that's how you're trying to play your Animation anyways.
    To check click on your Animation file and at the very top right of Inspector there is a little button to click on, change it to Debug and change your Animation to 1 I believe, that will make it Legacy Compatible.

    Once you make it Legacy compatible, make sure you have the "Animation" component on your player.
    and make a script the same way you made yours and it should work.

    If you want to do it through Mecanim system, then just make a float that works with the animation link from idle to run set to Speed = 0, then when your press W on Keyboard, make the script access your Animator component and change the Speed = 1 or something, but I'm not getting all into how to set it up, as its all over the net as well, just giving ideas.


    Oh and I had to add, do a debug log after you press W and then try a Debug Log After the Animation is supposed to play, just to see if the code is even being called.