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 Ben 39 · May 18, 2011 at 12:26 AM · decreaseliveslifegraduallyhealth

How to slowly decrease health script?

I have been looking for a script to slowly decrease the health of a player. (e.g when in a fire environment)

I currently have a basic script that will display the health bar, can anyone help me create a script to gradually reduce the players health?

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;

var LIVES = 21;

function Update () { switch(LIVES) { case 21: guiTexture.texture = health100; break;

      case 20:
          guiTexture.texture = health95;
          break;

      case 19:
          guiTexture.texture = health90;
          break; 

      case 18:
          guiTexture.texture = health85;
          break;

      case 17:
          guiTexture.texture = health80;
          break;

      case 16:
          guiTexture.texture = health75;
          break;

      case 15:
          guiTexture.texture = health70;
          break;

      case 14:
          guiTexture.texture = health65;
          break; 

      case 13:
          guiTexture.texture = health60;
          break;

      case 12:
          guiTexture.texture = health55;
          break;  

      case 11:
          guiTexture.texture = health50;
          break;

      case 10:
          guiTexture.texture = health45;
          break;

      case 9:
          guiTexture.texture = health40;
          break;

      case 8:
          guiTexture.texture = health35;
          break; 

      case 7:
          guiTexture.texture = health30;
          break;

      case 6:
          guiTexture.texture = health25;
          break;

      case 5:
          guiTexture.texture = health20;
          break;

      case 4:
          guiTexture.texture = health15;
          break;  

      case 3:
          guiTexture.texture = health10;
          break; 

      case 2:
          guiTexture.texture = health5;
          break;

      case 1:
          //gameover script here
          break;  
  }

}

EDIT***

After looking around some more I have come across a thread that seems relevant to what I want. But the problem Im having is combining the first script with the new one?

Slow Damage Over Time Script

Comment
Add comment · Show 1
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 Ben 39 · May 18, 2011 at 12:27 AM 0
Share

when pasting my code it seems to have messed up..sorry =\

3 Replies

· Add your reply
  • Sort: 
avatar image
1

Answer by Justin Warner · May 18, 2011 at 01:15 AM

Just subtract a life when player is in the fire... Check again in 3 seconds, and keep subtracting... Pretty easy.

Save the time, compare it with the refreshed time, but add 5 to the saved time, then that'll make it every 5 seconds...

Look around, easy.

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
avatar image
1

Answer by Dreamer · May 18, 2011 at 01:39 AM

I think what Ben wants is a health bar system replace of changing 21 pictures manually to represent current health.

Refer to below example of how to make a health bar:

http://answers.unity3d.com/questions/4456

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
avatar image
0

Answer by Ben 39 · May 20, 2011 at 12:15 AM

How would I use this code with the code above. Ive tried simply attaching the script to the player and tagging a sphere collider "Fire", but the code still does not work...any suggestions?

thanks for your help

 function OnTriggerStay(collisionInfo : Collider){
   if(collisionInfo.gameObject.tag == "Fire"){
   Health-=FireDamage*Time.deltaTime *1;
   enable = false;
   yield WaitForSeconds(1);
   enabled = true;
   }
  }
 } 
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

1 Person is following this question.

avatar image

Related Questions

Decrease Health every 5 mins or Time script? 2 Answers

How To Make Health Decrease 4 Answers

progress bar 1 Answer

How do I set a max limit for my health value? 4 Answers

Empty Health Bar, remove one life 2 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