- Home /
Decrease Health every 5 mins or Time script?
Hello there, i am new to unity. Just want to ask a question, are there any simple script for decreasing Health every 5 minutes? Even is there a time script where it shows time in the upper screen? i'm sorry about this im still learnning and if you could, Please tell me how :)
Many thanks!
               Comment
              
 
               
              Answer by MountDoomTeam · Dec 06, 2012 at 06:40 PM
this one should work straight up
 function OnGUI () {
   GUI.Box( Rect(10, 10, 300, 300)," ");
     GUI.Label (Rect (10, 10, 300, 300), " hi dude +0123\n  time ="+Time.time );
     }    
 
 //to decrease health every 5: have to add the variables if you can! :
 
 var delay = 500;//ms?
 function Start(){
 delayedtime = Time.time + delay;
 }
 function Update(){
 
 if (Time.time > delayedtime){health = health -1; delayedtime = Time.time + delay}
 }
 
 //you have to declare the variables at the top of the script, its only a few lines to figure out! learn that you learn alot!
Honestly, I think more answers should be like this. It helps you learn when you have to do a small part of the code :)
Answer by Eric5h5 · Dec 06, 2012 at 07:28 PM
Decrease health every 5 minutes:
 var health = 100;
 var healthReductionDelay = 300;  // seconds
 
 function Start () {
     InvokeRepeating ("DecreaseHealth", healthReductionDelay, healthReductionDelay);
 }
 
 function DecreaseHealth () {
     health--;
 }
Your answer
 
 
             Follow this Question
Related Questions
Problem with HealthBar 1 Answer
Health bar takes damage 1 Answer
How to Make Health Decrease Over Time 2 Answers
Reduce health constant 1 Answer
 koobas.hobune.stream
koobas.hobune.stream 
                       
                
                       
			     
			 
                