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
Sur cette page du site, vous pouvez voir la vidéo en ligne Reference Game Objects in Unity durée heure minute seconde en bonne qualité , qui a été Téléchargé par l'utilisateur Boxfriend 24 décembre 2021, Partagez le lien avec vos amis et connaissances, sur youtube cette vidéo a déjà été regardée 802 fois et il a aimé 33 téléspectateurs. Bon visionnage!