Example: there are objects A and B. Object A must connect with object B (by Script) and object B must connect with object A (by Script). How to do it more properly:
- Create Scripts for each objects.
- Create Empty Object and add one Script to it, and then in this Script to create two references (for A and B)?
CodePudding user response:
What you describe at section 2 is known as Mediator
pattern. You should definitely use it or you can also use Observer
pattern. The difference between them is there's a mediator between them which causes loosely coupling.
The common part between them is whenever an event happens to the object itself, it throws a callback and the other objects gets notified and do their own jobs.
To even make a better organization you can look at MVC(S) and ECS architectural pattern.