Health subtracts when hit by bullit

Hey i’m currently trying to make a 2D platformer, and i’ve reached the stage where i want to make the enemies work out, so what i’m currently strangling with is to make a script that subtracts my 1 of my ¨hearths¨ ( I have made a GUI-texture and placed out some hearths, and i’ve also made a enemy that shoots towards my character)

Here’s my healthcontroll script so far :

var health1 : Texture2D; //one life left

var health2 : Texture2D; //two life left

var health3 : Texture2D; //full heatlh

static var LIVES = 3;

function Update (){

switch(LIVES)

{	

case 3:

	guiTexture.texture = health3;

break;



case 2:

	guiTexture.texture = health2;

break;



case 1: 

	guiTexture.texture = health1;

break;



case 0:

	//game over script here

break;

}

}

So i know i’ll have to make script that will subtract my ¨LIVES¨, does anyone have a example of such a script? would love to get this scripting done :slight_smile:

The script was just to illustrate how far i’ve gotten, and the bullets are physic-based ¨spheres¨.

you can call a function in this script to detect any collision by doing:

 function OnCollisionEnter(collider: Collision) {
    LIVES--;
    }

or if you want to tag your Sphere to detect just when it hits the player you can attach a tag called “Sphere” in the sphere and make an if statement inside OnCollisionEnter function to check the tag of the collider, like:

  function OnCollisionEnter(collider: Collision) {
    if(collider.transform.tag == "Sphere") {
    LIVES--;
    }
    }