- Home /
Animation problem (noob)
Hey guys ;)
I wanna do simple animations (walk, run, jump).
I think that the script part is correct, but once I saved the script, I have an error:
Assets/Standard Assets/Scripts/Camera Scripts/Movecharacter.js(51,42): BCE0019: 'animation' is not a member of 'Object'.
Here is the script:
#pragma strict
var speed:float;
var speedRun:float;
var speedRotate:float;
var gravity:float;
var jumpspeed:float;
private var controller:CharacterController;
private var moveDirection:Vector3;
private var deltaTime:float;
private var characterContent;
private var runAnim:boolean;
private var run:boolean;
function Start () {
controller = GetComponent("CharacterController");
characterContent = transform.Find("samuzai");
}
function Update () {
deltaTime = Time.deltaTime;
runAnim = false;
if(controller.isGrounded){
if(Input.GetKey(KeyCode.LeftShift)){
moveDirection = Vector3(0,0,Input.GetAxis("Vertical") * speedRun);
runAnim = true;
}
else{
moveDirection = Vector3(0,0,Input.GetAxis("Vertical") * speed);
}
if(Input.GetKey(KeyCode.UpArrow) || Input.GetKey(KeyCode.DownArrow)){
if(!runAnim){
characterContent.animation.CrossFade("walk", 0.2);
}
else{
characterContent.animation.CrossFade("run", 0.2);
}
}
else{
characterContent.animation.CrossFade("idle", 0.2);
}
if(Input.GetKey(KeyCode.Space)){
moveDirection.y = jumpspeed;
characterContent.animation.CrossFade("jump", 0.2);
}
}
moveDirection = transform.TransformDirection(moveDirection);
transform.Rotate(Vector3(0,Input.GetAxis("Horizontal") * speedRotate * deltaTime,0));
moveDirection.y -= gravity * deltaTime;
controller.Move(moveDirection * deltaTime);
}
Thanks :)
Comment
Answer by Cherno · Nov 18, 2013 at 12:36 AM
Try to make characterContent a gameObject instead of a transform. Also, you could try and put the script that runs the animation directly onto the object that has these animations and see if that works.
Your answer
![](https://koobas.hobune.stream/wayback/20220613122109im_/https://answers.unity.com/themes/thub/images/avi.jpg)
Follow this Question
Related Questions
I am having two errors with my jump script 1 Answer
Different footstep sounds problem! 2 Answers
How to make animations only play with script? 1 Answer