How to change numbers in unity

hey i have a basic health script (e.g picture72958-screen-shot-2016-06-26-at-103527-pm.png) 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

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!