Trigger Collision Script

Hi everyone, I’m a fairly new Unity user, and I recently started writing my own scripts, and I have a trigger-collision problem. Simply enough, I want to write a script to make a mesh interact with a trigger, and I know how to do it by attaching the script to the trigger:roll_eyes:, but I need to attach the script to the mesh instead.:(.

I tried to use the "void OnTriggerEnter function, but it apparently only refers to triggers within the game object the script is attached to. Is there a way to reference an external trigger in a similar function?

I hope I was clear enough.

Anyone? :frowning:

I basically know I can attach this script to the trigger and detect the mesh, but I need to attach it to the mesh and detect the trigger instead

void OnTriggerEnter (Collision col)
{
if (col.gameObject.tag == “TriggerCube”)
{
Debug.Log (“Contact”);
contact = true;
}
}

OnTriggerEnter triggers on both the trigger, and the regular rigidbody contacting the trigger. I think your problem is your parameter: you’re using Collision (which is only sent when two non-triggers collide, via OnCollisionEnter). OnTriggerEnter takes a Collider instead. If the parameter is wrong, Unity won’t find the function, just as if you’d misspelled it.

1 Like

Ok, many many thanks, it’s working now! :slight_smile: