Understanding Unity OnColliderEnter() Object Management

Asked 1 years ago, Updated 1 years ago, 109 views

I've used OnColliderEnter() for behavior when "object with script attached" comes into contact with "something else". For example, do you attach OnColliderEnter() to the controller to determine that "other object" and "other object" come into contact?

I'm sorry that the question is hard to understand...

I want to know if I can handle OnColliderEnter() for other objects when I want to manage everything in the controller class.

unity3d

2022-09-30 21:14

1 Answers

You cannot take it directly.
(Of course, you can implement collision determination by yourself without using Collider, but that's different from what you intended, right?)

Therefore, if you want to write the logic of the collision on the controller,
1. Write the logic of the collision on the controller side (assume HandleCollisions())
2. Call Controller::HandleCollisions() in OnColliderEnter() of the actual gameObject to which the collider is attached
must be


2022-09-30 21:14

If you have any answers or tips


© 2024 OneMinuteCode. All rights reserved.