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 /
This question was closed May 25, 2014 at 11:54 AM by CrilleStyles for the following reason:

I fixed it myself

This post has been wikified, any user with enough reputation can edit it.
avatar image
0
Question by CrilleStyles · May 25, 2014 at 11:10 AM · guihealth

If health lower than 0 display gui

How do I display gui saying "You died" If the health is lower than 0?

 #pragma strict
 
 var tex1 : Texture;
 var tex2 : Texture;
 var tex3 : Texture;
 var tex4 : Texture;
 
 var health : float = 100.0;
 
 private var maxHealth : float = 100.0;
 private var enterCollider : boolean = false;
 
 //Damage Collider
 function OnTriggerEnter (Col : Collider)
 {
     if(Col.gameObject.tag == "Player")
     {
         enterCollider = true;
         Debug.Log("Is inside collider");
     }
 }
 
 function OnTriggerExit (Col : Collider)
 {
     if(Col.gameObject.tag == "Player")
     {
         enterCollider = false;
     }
 }
 
 function Update ()
 {
     //Health countdown whilst in the damage collider
     if(health > 0 && enterCollider == true)
     {
         health -= Time.deltaTime * 20;
     }
     
     //Normal health regeneration
     if(health >= 0 && enterCollider == false)
     {
         health += Time.deltaTime * 2;
     }
     
     //When health reaches 100, set to maxHealth
     if(health > maxHealth)
     {
         health = maxHealth;
     }
 }
 
 function OnGUI ()
 {
     if (health <= 100)
     {
         GUI.DrawTexture(Rect(0,0, Screen.width, Screen.height), tex1);
     }
     
         if (health <= 80)
     {
         GUI.DrawTexture(Rect(0,0, Screen.width, Screen.height), tex2);
     }
     
         if (health <= 40)
     {
         GUI.DrawTexture(Rect(0,0, Screen.width, Screen.height), tex3);
     }
     
         if (health <= 10)
     {
         GUI.DrawTexture(Rect(0,0, Screen.width, Screen.height), tex4);
     }
 }
 
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 ABerlemont · May 25, 2014 at 11:19 AM 0
Share

add a 5th texture and add

if(health

at the end of the OnGUI() function ??

0 Replies

  • Sort: 

Follow this Question

Answers Answers and Comments

21 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

The Game Over creating with audio? 1 Answer

Health Bar Centering 4 Answers

Trubble with my hit counter. 0 Answers

Restart with GUIText 2 Answers

There is no 'GUITexture' attached to the "Player Character Prefab(Clone)" game object, but a script is trying to access it. 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