Move to object if collision is triggered
I am trying to make it so when an object with tag "Enemy" enters a collider he gets marked and object with the script on it moves towards it. (Even if the enemy moves and moves out of collider)
Script I have so far:
#pragma strict
private var HR : int; //Homing Range
private var Enemy : boolean;
function Start () {
Enemy = false;
HR = PlayerPrefs.GetInt("ECS.Homing");
GetComponent.< SphereCollider >().radius = HR;
}
function Update () {
if (Enemy) {
//Home In
}
}
function OnTriggerEnter (collider:Collider) {
if (collider.tag == "Enemy") {
Enemy = true;
GetComponent(SphereCollider).enabled = false;
}
}
I'm not sure how to save the single transform of the enemy object that triggered collision and I don't know how to even search for this please help.
Comment