- Home /
I need a character animation script
my character has a seperate move script and I want to animate it. I need the animation script that makes it that you press a key and it animates just a code would do also. Please help
Answer by $$anonymous$$ · Jul 14, 2015 at 02:29 PM
The animation.Play()
function is deprecated. Use this instead.
function Update ()
{
if(Input.GetKey(KeyCode.W))
{
GetComponent.<Animation>().Play("walk");
}
else
{
GetComponent.<Animation>().Play("idle");
}
}
I would HIGHLY recommend using an animator if you want transitions between animations.
Also, I just recently started writing scripts for free for anyone who needs them. Email me at duskerstudios@gmail.com if you want a scripter.
Answer by GesterX · Feb 18, 2011 at 10:55 PM
This page explains clearly how you would script input based animation events:
http://unity3d.com/support/documentation/Manual/Animation%20Scripting.html
So for example:
function Update () {
if (Input.GetAxis("Vertical") > 0.2)
animation.CrossFade ("walk");
else
animation.CrossFade ("idle");
}
This plays the animation "walk" when the player moves forward or backwards.
i tried using this script but in unity it says erorr for else i wanted to make the charatr move forward and play the naimation. i found this script and was wondering if you could help me it says "error", what should i do
Your answer
![](https://koobas.hobune.stream/wayback/20220613105117im_/https://answers.unity.com/themes/thub/images/avi.jpg)