i saw this script on a video and it worked perfectly for him but not for me. when i do it, i get an error saying: The animation state idle could not be played because it couldn't be found!Please attach an animation clip with the name 'idle' or call this function only for existing animations. how do i fix this?
this is the script:
#pragma strict
var rotationSpeed : float = 10;
var walkSpeed : float = 7;
var gravity : float = 50;
private var yRot : float;
var body : Transform;
function Update () {
var controller : CharacterController = GetComponent(CharacterController);
var vertical : Vector3 = transform.TransformDirection(Vector3.forward);
var horizontal : Vector3 = transform.TransformDirection(Vector3.right);
var height : Vector3 = transform.TransformDirection(Vector3.up);
if(Input.GetAxis("Vertical") || Input.GetAxis("Horizontal")){
animation.CrossFade("walk 001",0.2);
controller.Move((vertical * (walkSpeed * Input.GetAxis("vertical"))) * Time.deltaTime);
controller.Move((horizontal * (walkSpeed * Input.GetAxis("Horizontal"))) * Time.deltaTime);
}else{
animation.CrossFade("idle",0.2);
}
if(Input.GetAxis("Mouse X")){
yRot += 10 * Input.GetAxis("Mouse X");
}
transform.rotation = Quaternion.Euler(0, yRot, 0);
controller.Move(height * gravity * Time.deltaTime);
}
function LateUpdate(){
// Rotate the Character to match the direction he/she is going
if(Input.GetAxis("Vertical") == 0){
if(Input.GetAxis("Horizontal") > 0){
body.localEulerAngles.y = 180;
}else if(Input.GetAxis("Horizontal") < 0){
body.localEulerAngles.y = 0;
}
}else if(Input.GetAxis("Vertical") > 0){
if(Input.GetAxis("Horizontal") > 0){
body.localEulerAngles.y = 135;
}else if(Input.GetAxis("Horizontal") < 0){
body.localEulerAngles.y = 45;
}
}else if(Input.GetAxis("Vertical") < 0){
if(Input.GetAxis("Horizontal") == 0){
body.localEulerAngles.y = -90;
}else if(Input.GetAxis("Horizontal") > 0){
body.localEulerAngles.y = -135;
}else if(Input.GetAxis("Horizontal") < 0){
body.localEulerAngles.y = -45;
}
}
}
please can somebody tell me how to fix this?
↧