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 shelin · Dec 15, 2010 at 08:32 AM · animationguihealthbar

Healthbar is over play dead Animation

I want to healthbar over can play animation. How can I do?

this my healthbar.js

var health100:Texture2D; var health95:Texture2D; var health90:Texture2D; var health85:Texture2D; var health80:Texture2D; var health75:Texture2D; var health70:Texture2D; var health65:Texture2D; var health60:Texture2D; var health55:Texture2D; var health50:Texture2D; var health45:Texture2D; var health40:Texture2D; var health35:Texture2D; var health30:Texture2D; var health25:Texture2D; var health20:Texture2D; var health15:Texture2D; var health10:Texture2D; var health5:Texture2D; var health0:Texture2D;

function OnGUI () { if (GeneralVars.blood <=100 &&GUI.Button (Rect (450,425,50,25), "restart")) { GeneralVars.blood = 100; Application.LoadLevel(1); script = GetComponent(HealthBarPicture); script.DoSomething (HealthBarPicture); } }

function Update () {

if(GeneralVars.blood ==100) this.guiTexture.texture = health100;

else if(GeneralVars.blood >=95 && GeneralVars.blood <100) this.guiTexture.texture = health95; else if(GeneralVars.blood >=90 && GeneralVars.blood <95) this.guiTexture.texture = health90;

else if(GeneralVars.blood >=85 && GeneralVars.blood <90) this.guiTexture.texture = health85; else if(GeneralVars.blood >=80 && GeneralVars.blood <85) this.guiTexture.texture = health80;

else if(GeneralVars.blood >=75 && GeneralVars.blood <80) this.guiTexture.texture = health75; else if(GeneralVars.blood >=70 && GeneralVars.blood <75) this.guiTexture.texture = health70;

else if(GeneralVars.blood >=65 && GeneralVars.blood <70) this.guiTexture.texture = health65; else if(GeneralVars.blood >=60 && GeneralVars.blood <65) this.guiTexture.texture = health60;

else if(GeneralVars.blood >=55 && GeneralVars.blood <60) this.guiTexture.texture = health55; else if(GeneralVars.blood >=50 && GeneralVars.blood <55) this.guiTexture.texture = health50;

else if(GeneralVars.blood >=45 && GeneralVars.blood <50) this.guiTexture.texture = health95; else if(GeneralVars.blood >=40 && GeneralVars.blood <45) this.guiTexture.texture = health40;

else if(GeneralVars.blood >=35 && GeneralVars.blood <40) this.guiTexture.texture = health95; else if(GeneralVars.blood >=30 && GeneralVars.blood <35) this.guiTexture.texture = health30;

else if(GeneralVars.blood >=25 && GeneralVars.blood <30) this.guiTexture.texture = health25; else if(GeneralVars.blood >=20 && GeneralVars.blood <25) this.guiTexture.texture = health20;

else if(GeneralVars.blood >=15 && GeneralVars.blood <20) this.guiTexture.texture = health15; else if(GeneralVars.blood >=10 && GeneralVars.blood <15) this.guiTexture.texture = health10;

else if(GeneralVars.blood >=5 && GeneralVars.blood <10) this.guiTexture.texture = health5;

else if(GeneralVars.blood <5 &) this.guiTexture.texture = health0; animation.Play( "dead" );

  }

I Cannot play dead animation in game over. How can I do?

Comment
Add comment · Show 2
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 zannghast · Dec 15, 2010 at 08:44 AM 0
Share

Apart from having the potential to be refactored and made more efficient, what is wrong with your code above? What do you want to know exactly?

avatar image oliver-jones · Dec 15, 2010 at 12:10 PM 0
Share

Yeahhh, I not really understanding the question either?

1 Reply

· Add your reply
  • Sort: 
avatar image
0

Answer by Statement · Dec 15, 2010 at 12:32 PM

If your code otherwise works, but you won't know how to animate the change over time; This is easily done in an update or co routine.

GeneralVars.blood = Mathf.MoveTowards(GeneralVars.blood, blood, Time.deltaTime);

where blood is a variable that you set on damage. Alternatively you can change so

// private member to help track the animated blood value private var blood : float = 0;

// set the blood value to move towards GeneralVars.blood blood = Mathf.MoveTowards(blood, GeneralVars.blood, Time.deltaTime);

because I think it'll fit into your system easier. Then your gui code be changed;

// old style: else if(GeneralVars.blood >=55 && GeneralVars.blood <60) this.guiTexture.texture = health55;

// new style (use blood variable): else if(blood >=55 && blood <60) this.guiTexture.texture = health55;

But I really suggest you refactor your code first since it's just a pain and nightmare to work with a method that large.

Comment
Add comment · 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

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

Problem with GUI animation transitioning. 1 Answer

GUI button is moving/disappearing when animation is played 0 Answers

(Unity 4.6) Button animations 1 Answer

GUI, SpellBar and C#-related questions 1 Answer

Scrollbar Thumb Scaling 0 Answers


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