Home > Net >  How properly organize workspace in Unity?
How properly organize workspace in Unity?

Time:10-22

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:

  1. Create Scripts for each objects.
  2. 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.

  • Related