x


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.

more ▼

asked Jul 27 '11 at 04:06 PM

Sadakos Boyfriend gravatar image

Sadakos Boyfriend
3 4 4 7

(comments are locked)
10|3000 characters needed characters left

1 answer: sort voted first

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.

more ▼

answered Jul 27 '11 at 05:55 PM

Chris D gravatar image

Chris D
2.5k 5 7 25

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:

http://blenderartists.org/forum/showthread.php?226055-Preparing-blender-files-for-exporting-to-unity...&p=1910839

Thank you for your help :)

Jul 27 '11 at 06:08 PM Sadakos Boyfriend

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.

Jul 27 '11 at 06:11 PM Chris D
(comments are locked)
10|3000 characters needed characters left
Your answer
toggle preview:

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this question

By Email:

Once you sign in you will be able to subscribe for any updates here

By RSS:

Answers

Answers and Comments

Topics:

x1949
x70
x18

asked: Jul 27 '11 at 04:06 PM

Seen: 645 times

Last Updated: Jul 27 '11 at 06:11 PM