- Home /
Animation Help Needed (Method Not Found)
I am trying to add a walking animation to my charachter but when I try it says "MissingMethodException: Method not found: 'UnityEngine.Animation.play" I dont know what to do. here is my script
var character: CharacterController;
var speed: float = 5.0; // moving speed
var direction: float = 1; // direction (-1 means -x)
var directionback: float = -1;
var runanimation: AnimationClip;
var placeanimation: AnimationClip;
var attackanimation: AnimationClip;
var dieanimation: AnimationClip;
function Start(){
character = transform.GetComponent(CharacterController);
}
function Update(){
if(Input.GetKey("d")){
character.Move(Vector3.forward * speed * direction * Time.deltaTime);
animation.play(animation.clip.runanimation);
}
if(Input.GetKey("a")){
character.Move(Vector3.forward * speed * directionback * Time.deltaTime);
}
if(Input.GetKey("w")){
character.Move(Vector3.right * speed * directionback * Time.deltaTime);
}
if(Input.GetKey("s")){
character.Move(Vector3.right * speed * direction * Time.deltaTime);
}
}
can someone plz help me. I have no idea what to do.
Answer by syclamoth · Oct 02, 2011 at 06:08 AM
You need to spell 'play' with a Capital P!
Also, animation.clip.whatever isn't the correct way of getting the animations- you should use whateverYouCalledYourAnimationClip.name; - this returns a string which can be plugged into animation.Play.
Like so-
animation.Play(runanimation.name);
animation.Play(attackanimation.name);
I put it it in and it says now the animation state could not be played because it could not be found?
$$anonymous$$ake sure that your Animation component has all of the named AnimationStates attached to it. Look at the 'Animations' dropdown inside the Animation component.
all of them are named the code now says animation.Play(runanimation.runn) (runn) is the name of the animation
oooohhhh, no that's not what I meant.
I meant, runanimation.name, as in just that- the name doesn't get replace with anything, since it automatically turns into whatever the name of the animation is!
Answer by Grady · Oct 02, 2011 at 06:06 AM
Your problem here is that you made a mistake that can be easy to make.
To play your animations, you wrote animation.play()
. What you should have written was animation.Play()
with a captial P!!!!
Just swap every animation.play()
with the capital P. Here is the script reference for animation.Play()
: http://unity3d.com/support/documentation/ScriptReference/Animation.Play.html
Hopefully this will fix your issue!!!! :D
If not, then comment back and I will try and help you more!
-Grady
There's another problem in there as well, but that's in my answer!
Your answer
Follow this Question
Related Questions
Playing an Animation that is within a GameObject 1 Answer
The name 'Joystick' does not denote a valid type ('not found') 2 Answers
Trying to check what anim clip is currently running on object 1 Answer
Empty animation clips when copying to Prefab 1 Answer
How can I reassign animation curves to play on a child object (instead of through parent)? 1 Answer