- Home /
How do I check which prefabs are colliding
I have a prefab class I spawn 20 times. After they're spawned, they can "collide" with each other, ontriggerenter maybe. When they collide, something should happen at the position they're standing.
How do I check which ones are colliding? Because collision only works with monobehaviour? or not?
I think there's some confusion here. Builtin collision only works through GameObjects with Collider components (provided at least one of the objects colliding contains a Rigidbody). You can access that collision information (and then which colliders touched) through the argument passed by that event.
void OnCollisionEnter(Collision collision)
{
// Use the Collision instance here to do something like
Debug.LogFormat("{0} collided with {1}", this.name, collision.gameObject);
}
Answer by Topthink · Mar 11, 2019 at 04:54 PM
Debug.Log("Some Text Here"); ... Spread those around your program … among the "On Trigger" and "On Collision" parts of your code. If you have your script attached to something just put that in the Debug Log … something like "Script attached to Child of Player" or "Enemy prefab sphere collider" or something that will help you narrow down where your contact is occurring.
... Anyway, I've done that in the past and it generally works well for me although I don't know your exact situation.