Unity mystery:

1) In a new scene, create a cube. Give it scale 5,5,5, a transparent material, and make its BoxCollider a trigger.
2) Create a sphere inside the cube. Give it a RigidBody with no gravity.
3) Attach this script to the cube:
public class Hark : MonoBehaviour
{
private void OnCollisionStay(Collision other)
{
if (other.gameObject.name != "Ground")
{
Debug.Log(other.gameObject.name);
}
}
}
When run, shouldn't the cube detect the sphere inside it? Why doesn't it? How can I detect that?

Follow

@peterdrake Because when a trigger is involved, OnTriggerX gets invoked instead of OnCollisionX.

See the chart at the bottom of this page: docs.unity3d.com/Manual/Collid

Sign in to participate in the conversation
Qoto Mastodon

QOTO: Question Others to Teach Ourselves
An inclusive, Academic Freedom, instance
All cultures welcome.
Hate speech and harassment strictly forbidden.