HP

Author: Sobhan Bahrami

Description
This tutorial is for "Adding HP to your Enemy and Explode it!!"

i wrote it with help of some Unity Users In MIRC (Unity Public Chat )

we decide to put it here for Security resons

ok you have to Do following things to get the result :

Add this script to your enemy: Make sure your enemy have collisions, rigidbody or box collider.

And you bullet Perfab Most have "Box Collider, rigidbody.

Note : Please Do not Made an Illegal Copy Of this Article .

thanks, S. Bahrami

JavaScript


var damage = 5; // take 5 hit of damage every bullet collision. var health = 100; //can have more than 100 of health. var explosion : Transform; // The explosion perfab

function OnCollisionEnter(collision : Collision) { if (health <=0) { Destroy(gameObject); // destroy the object of the scene var exp = Instantiate(explosion, gameObject.transform.position, Quaternion.identity); //Start the explosion. BroadcastMessage("IsGone"); // Show the message notification. } health = health - damage; // get down the damage. }