how to make enemies have health and get damaged by bullets

i need a code that will make my enemies get damaged when they are hit by my bullets. I have not put health or anything on the yet apart from a collider.

May i suggest you to use raycastgun because it is way better and you can add penetration too

Heres is the damage script

var health:float = 90;

function Damage(dmg:float){
health -= dmg;

function Update (){
if(health <=0){
//add your death code


Add this code to your bullet

var dmg:float = 20;

function OnTriggerEnter(hit:Collider){
if(hit.tag == "Enemy"){


assign the tag Enemy to the object you added the Damage script

I’d also look into Survival Shooter - Unity Learn its a follow along tutorial by Unity a couple years ago (check the attached PDF in the assets for specific unity 5 updates) and it goes over setting playerhealth/enemy health and taking damage.

Has some good starter scripts to look at as well.

To do a death code use this

if(health <= 0)
//Play a death anim or