x


change model state due to health

Hi all,

Been trying to find an answer for this for a while and im currently having a brain freeze.

I have a model which has 5 frames of animation. frame 1 its fine, frame 2 dented, frame 3 more dented, frame 4 more damaged and frame 5 crushed.

I've also created a health var for it.

What i want is when that health drops to under 80 the model changes to frame 2. If the health drops under 60 the model changes again to the next frame and so forth.

Does anybody know how to do it please?

I do apologies if im being thick. But its driving me slowly mad. If it helps i do own Unity Pro.

Thank you in advance.

more ▼

asked May 27 '10 at 07:40 PM

Gavrok gravatar image

Gavrok
15 4 4 6

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

1 answer: sort voted first

The way I would do it is break up the animation into separate animation clips and name them accordingly. I'd set their wrap mode to clamp forever as well.

Then you make sure your model's game object has an animation component attached to it and it has reference to the aforementioned animation clips.

From there it is simply a matter of implementing a conditional statement in your script where you accumulate your damage.

Note: You might have to adapt this to suit your Game Object structure, as I am operating under the assumption that the script in which you accumulate damage is a component of the same Game Object that your animation component is attached to.

if(health < 20)
{
    animation.Play("animationnamehere");
}
else if(health < 40)
{
    //so on and so forth
}
else if(health < 60)
{
    //so on and so forth
}

Notice in my script I am working backwards, this is because if you did it the other way( if(health < 90) ) it will return true on that case for everything less than 90 and you wont see the state change because your logic is flawed.

Just a note that there are FAR more efficient ways to do this but I am working here for the sake of simplicity.

Hope that helps.

==

more ▼

answered May 27 '10 at 11:31 PM

equalsequals gravatar image

equalsequals
4.5k 16 28 64

I Like simplicity :) Thankis for the speedy response, I shall give it a go when i get a chance and let you know the outcome.

Thank you again.

May 28 '10 at 06:30 AM Gavrok
(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:

x3776
x383
x248
x58
x54

asked: May 27 '10 at 07:40 PM

Seen: 1638 times

Last Updated: May 27 '10 at 07:40 PM