Reference Game Objects in Unity

Опубликовано: 24 Декабрь 2021
на канале: Boxfriend
802
33

These are some of the best ways to reference game objects in the Unity engine. There are other methods of getting a reference such as the GameObject.Find and GameObject.FindObjectsOfType methods, but those methods are generally slow because they need to traverse the hierarchy to find the object and you don't get to choose which object it finds if you have multiple that match the parameters of the search.

My thoughts on the Singleton pattern:
It's a great design pattern and can be incredibly useful. However a lot of new game developers tend to overuse them and make everything a singleton just for easy references. This is bad practice, only use the singleton pattern when it is actually necessary, for example your UI doesn't need to be a singleton, it can subscribe to events to get updates from your player or other objects.

For more info about events, take a look at these resources:

Unity Learn: https://learn.unity.com/tutorial/even...

Jason Weimann on C# Events or UnityEvents:    • Events or UnityEvents?????????  

TIMESTAMPS
00:00 Serialized References
01:26 Singleton Pattern
03:09 Dependency Injection
05:07 Events


На этой странице сайта вы можете посмотреть видео онлайн Reference Game Objects in Unity длительностью часов минут секунд в хорошем качестве, которое загрузил пользователь Boxfriend 24 Декабрь 2021, поделитесь ссылкой с друзьями и знакомыми, на youtube это видео уже посмотрели 802 раз и оно понравилось 33 зрителям. Приятного просмотра!