How to change numbers in unity
hey i have a basic health script (e.g picture ) witch destroys the player when reached 0 so i was wondering if you could figure out how to when the bullet collides with player take away 30 point of the script......... i would be very grateful if you help
) witch destroys the player when reached 0 so i was wondering if you could figure out how to when the bullet collides with player take away 30 point of the script......... i would be very grateful if you help
here is the health script:
 var curHealth : int = 100; var maxHealth : int = 100;
 
 function Start () { }
 
  function Update()
  {
      // if the player is dead destroy him
      if(curHealth <= 0)
          Destroy(gameObject);
      // if curHelath < 0 -> curHealth = 0; if curHealth > 100 -> curHealth = 100
      curHealth = Mathf.Clamp(curHealth,0,100);
  }
hope this helps thanks
.harry
Hey harry. When you post a question that has code, please highlight your pasted code and then click the "101/010" button in the formatting toolbox above the text editor. You'll notice I've already done this for you, and your question looks a lot more roomy and readable because of it!
Please do this in the future, and you'll get upvoted and answered more often :)
Answer by phxvyper · Jun 26, 2016 at 03:18 PM
You can subtract values from properties and variables using basic maths arithmetic:
 curHealth = curHealth - 30;
As an example of implementation, you could do this on key press:
 function Update() {
     ...
     if (Input.GetKeyDown(KeyCode.G)) {
         curHealth -= 30;
     }
     ...
 }
Whenever you press G on your keyboard, curHealth should decrease by 30!
thank you so much you have helped me a lot thank you!!!!!! (ノ◕ヮ◕)ノ*:・゚✧
Your answer
 
 
             Follow this Question
Related Questions
Health Script 2 Answers
Interesting Script Problem 1 Answer
Unity: Player take damage from enemy projectile 2 Answers
How do I do a Immunity time after being hited? 2 Answers
Health pickup script issue -1 Answers
 koobas.hobune.stream
koobas.hobune.stream 
                       
                
                       
			     
			 
                