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.

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.