- Home /
Walking Animation Won't Work :(
Hi, so i have a walking animation for my player which is the main camera on the player moving up and down to simulate walking. I have a script to execute this so it only plays when the player is "walking" but it wont work when i test it out.
Script:
pragma strict
function Update () {
if (Input.GetButtonDown ("Horizontal"))
{
Camera.main.animation.Play("walking");
}
}
and i have the animation and the script both put in the "Main Camera"
Thank you for your help.
try placing the script on the object that has the animation rather then the camera
Answer by Cataclysm Entertainment · Aug 21, 2014 at 08:26 AM
Hi TcGreyson, To make it working, you don't need to use Camera.main.animation.Play();. You can use directly animation.Play(); with the animation component attached to your camera. Next you just put your animation in the animation field and normally it's working.
However you have an other way : you can use AnimationCurve.Evaluate(); Like that :
pragma strict
var walkCurve : AnimationCurve;
function Update () {
if (Input.GetAxis("Horizontal") {
transform.rotation.z = AnimationCurve.Evaluate();
}
}
It make your camera moving when you press the horizontal axis. With that you don't need to create animation files, all is stored in variables !
PS : Sorry if my script is wrong, But the idea is here.
Thank you for the answer. I tried method 1 and changed it to animation.Play(); and i got this error:
Assets/walking_and_running.js(8,27): BCE0034: Expressions in statements must only be executed for their side-effects.
i tried figuring out what it meant but im really tired and couldn't find out :( any ideas on what this means?
Your answer
Follow this Question
Related Questions
Multiple Cars not working 1 Answer
Reloading Help 2 Answers
Animation spins wildly after completed 0 Answers
Animation triggered by an animation? 1 Answer
cant play 3rd person animation 0 Answers