Clone position

Hello. This is my script for a the hill (as in king of the hill) type area in my game. In it, I check to see if the player object is within a certain distance of the hill object, if it is then I activate the player’s weapons. It works fine, until I try to instantiate multiple clones of the hill. It only registers for the newest hill spawned, how can I make it so that if the player is within a set distance of any of the instantiated hills “weapon” variable is changed?

var player : Transform;

function Update () {
   var distance = Vector3.Distance(player.position, transform.position);
   if (distance > 10.0f) {Hotspot_W.weapon=0;}
   if (distance < 10.0f) {Hotspot_W.weapon=1;}
}

Make your hill a trigger zone with

function OnTriggerEnter( other : Collider ) {
  if ( other.GetComponent( Player ) ) {
    other.GetComponent(Player).weaponEnabled = true;
  }
}

function OnTriggerExit( other : Collider ) {
  if ( other.GetComponent( Player ) ) {
    other.GetComponent(Player).weaponEnabled = false;
  }
}

Change the variable names as needed of course.

Thanks :slight_smile: