OnTriggerEnter (66213)

Hey all,

This is such a noob question, I have used this code before I even copied it from another project I was working on.

var target : Transform;    

function Start () {    
}

function Update () {    
}

function OnTriggerEnter (trig : Collider){
	if(trig.gameObject.tag == "enemy"){
			Debug.Log("Detected!");
	}
}

It’s not rocket science is it? But this is attached to a sphere with a trigger, and I have another object Tagged enemy. But it simply will not Debug.

This is probably a school boy error but I can’t make it work. please help!

Steve

Does enemy have a rigidbody? Only rigidbodies will "trigger" a trigger collider.

1 Answer

1

Hi MrSteave1
Collision or Trigger detect when only one of the object have rigid-body, so please add rigid-body component any of the one game object…

"when only" should read "when at least"

thanks fafase to correct my mistake, my knowledge inEnglish is not good