Detect OnCollisionEnter from non MonoBehaviour class.

Greetings,

I have a class with a GameObject variable. The class doesn’t inherit from any other class. The GameObject has a a Rigidbody and a BoxCollider components.

public class Example {
        private GameObject gameObject;

        public Example () {
                // init gameObject
                // add Rigidbody
                // add BoxCollider
        }

       // How can I detect OnCollisionEnter in this class?

}

Is there any way of detecting OnCollisionEnter in this class; because the class doesn’t inherit from MonoBehaviour, I am not sure how to do it.

Appreciate your help.

Thank you,
Jude

You have to define OnCollisionEnter in a MonoBehaviour. However, you can just have the only thing in that method be an event call, and you can subscribe to that event in Example’s constructor.