- Home /
Problem with animation code or blender?
I imported a blender file (a basic running animation)into Unity as a .FBX file.
I've used some code which i thought might play the animation when a key is pressed, but im just getting an error message: "unknown identifier: 'blockgoatrun'" ('blockgoatrun'being the name of the blender model import).
Here is the code:
var Speed = 5.0;
function Update () {
if(Input.GetKey("d")) {transform.Translate(transform.forward Speed Time.deltaTime); animation.Play(blockgoatrun); } }
Why isn't it recognising the file?
I know im making some fundamental error as i am still new to all this, im just buggered if i know what it is!
Thank you, Tom.
Answer by Chris D · Jul 27, 2011 at 05:55 PM
If that's your complete code, the problem is that you're calling Play on the animation stored in the variable blockgoatrun
which probably doesn't exist. Check out the docs on Play() here.
If the animation is attached to the gameobject already, just replace animation.Play(blockgoatrun)
with animation.Play("blockgoatrun")
. Play requires a string.
That did indeed fix the code, thank you :)
The animation doesnt seem to exist (like you sugested), so im probably doing somthing else wrong in Blender.
If you fancy taking a look, i asked for help on a Blender forum:
Thank you for your help :)
No problem, glad to be of assistance. If you mark this solution as accepted (check box next to the thumbs), others will know that you've found an answer and it may be of some help to someone in the future.