I would like to detect a collision between my character and two specific other objects. The objects are basically triggers to detect if my characters is in a specific location and return a bool value. I’m think some way with the OnTriggerEnter() class, but I do not know how to check whether object entering is the player or not and the objects are in motion. the link below is to a test version of the scene I’m working on and the red meshes rotating are what I’d like to detect collision with.
when using:
OnTriggerEnter(Collider col)
{}
this is attached object A (any object, who cares) then object B enters in collision with A. The script is on A but col is a reference to B of type Collider. So for instance if you want to check the name of the other object:
OnTriggerEnter(Collider col)
{
if(col.collider.name == "ObjectB")
{
// It is object B
}
}
if you want to recognize a group of object based on tag:
OnTriggerEnter(Collider col)
{
if(col.collider.tag == "TagB")
{
// It is object tagged with TagB
}
}
When you use OnTriggerEnter() or OnCollisionEnter() the parameters should be (Collision tempParamName)
Then your object should have a “tag” or “name” you can compare the collision with for example:
OnTriggerEnter(Collision sphere)
{
if(sphere.tag == "redMesh")
debug.log("collided with redMesh");
}