OnTriggerEnter either not working or broken

Hi everyone, I am having troubles with OnTriggerEnter. I have 4 prefabs with 2 colliders, a sphere collider (with trigger enabled) and a box collider. I have a script that enables another script that makes that object follow another.

However, it does not work. It simply gets enabled as soon as I hit play.

var health : int = 100;
var attackThreshold = 5.5;
var attackRepeatTime = 1;
var lockPos : float = 0;
var Timer = 0.0;
var target : Transform;
var myTransform : Transform;
function Awake(){
    myTransform = transform;
}
function Update(){
    var distance = (target.transform.position - this.gameObject.transform.position).magnitude;
    if(distance > 2.1){
        this.gameObject.animation.Play("ZFollow");
    }
   
    transform.rotation = Quaternion.Euler(lockPos, transform.rotation.eulerAngles.y, transform.rotation.eulerAngles.z);
    if (distance < 2){
        Timer += Time.deltaTime;
        this.gameObject.animation.Play("ZAttack");
        pControl.health -= Time.deltaTime;
        Timer = 0;
    }
}

function OnTriggerEnter(){
    this.gameObject.GetComponent("SteerForTarget").enabled = true;
    this.gameObject.GetComponent("AutonomousVehicle").enabled = true;
   
}

Any idea how to fix?

Try printing to see what it hits:

function OnTriggerEnter (other : Collider) {
Debug.Log(other.transform.name);
}
1 Like

Hey, it’s showing up every single collider there is around the object.
I should use tags to make sure it’s only the player?

Edit:

Fixed now haha, haven’t used Unity in a while so iv’e forgotten some stuff ^^