Say for example I have a health script. In inspector I should be able to assign a game object like an enemy so when the player collides within range of it the health decrease. However what if I have multiple enemies. How do I assign all of them in ‘target’ in the inspector.
#pragma strict
var range : int;
var target : GameObject;
var health : int=100;
var customGuiStyle : GUIStyle;
function Start () {
}
function Update () {
}
function OnCollisionEnter(info : Collision){
range=Vector3.Distance(target.transform.position,transform.position);
if (range<5){
health-=4;
}
if (health<=0){
yield WaitForSeconds(1);
Destroy(gameObject);
}
}