Click to animate object not working

I have imported a max file into Unity which contains two simple boxes. These boxes both have animations which simply rotate them individually 90 degrees. In Unity I am trying to get to a situation where I can click on Box01 and Box01’s animation plays and similarly when I click on Box02 Box02’s animation plays. If I put a collider over the group it allows me to click and run either animation but that only gives me on clickable item. If I apply a collider to both boxes and attach a script to each box it runs the correct scripts but does not display the animations.

The two boxes are called Box01 and Box02 with their animations being called bx01 and bx02.
The following two scripts are linked to each box which when clicked does indeed print out the relevant messages but does not animate. No error messages are displayed.

function OnMouseDown ()
{
animation.Play(“bx01”);
print(“Played 01”);
}

function OnMouseDown ()
{
animation.Play(“bx02”);
print(“Played 02”);
}

I have been searching for the answer for this for days and cannot work it out. Can anybody shed some light on this problem?? Its driving me nuts!!!

are you importing both boxes in as the same max file? they prob have to be different files, its likely that they are sharing the animation information, and when separated it gets messed up,

try 2 different max files

Yeah they are in the same file. Unfortunately they need to be in the same file. The actual max file I want to use contains over a hundred objects with multiple animations. If I cant find a way to get it to work it is going to cause a huge headache separating out all the individual models. It looks like it should work but it juuuust doesnt quite.

ok so i ran a lil test and got it working :wink:

your whole max file is the one that contains the animation information, not your cube, so you need to tell it to play the animation from the main parent of your maxfile

so say your maxfile is called CubeFile ok?

your script will be

var CubeFile : Transform;

function OnMouseDown ()
{
CubeFile.animation.Play("bx01");
print("Played 01");
}

then drop your whole max file from your scene into the transform variable, and it should play each animation separately :smile:

i also noticed that if you click on 1 box then the other box before the 1st animation is finished playing, it freezes the animation up. so youll have to separate your animations onto different layers by making a new script and putting it on your grouped object

animation["bx01"].layer= 1;

Oh you absolute star!!! Yep got is working now. My hair is now safe from being torn out :slight_smile:

Thanks, you’re a life saver!

Duncan