Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 13 Next capture
2021 2022 2023
1 capture
13 Jun 22 - 13 Jun 22
sparklines
Close Help
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
avatar image
0
Question by Gavrok · May 27, 2010 at 07:40 PM · animationdamagevaluesstatehealth

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.

Comment
Add comment
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users

1 Reply

· Add your reply
  • Sort: 
avatar image
0
Best Answer

Answer by equalsequals · May 27, 2010 at 11:31 PM

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.

==

Comment
Add comment · Show 1 · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image Gavrok · May 28, 2010 at 06:30 AM 0
Share

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.

Your answer

Hint: You can notify a user about this post by typing @username

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

Answers Answers and Comments

No one has followed this question yet.

Related Questions

Not identifying the collider? 2 Answers

Enemy Ragdoll help 1 Answer

Ranged damage not working 1 Answer

Help playing the right animation 1 Answer

Health and damage reciever 1 Answer


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges