A common choice is to use the objects name, either with the GameObject.Find method, which will look through all the objects in the scene, or by searching through the names of another GameObjects children for a match. Remember this the next time you see GameObject.Find in your codebase.ĭiscussion can be found on the r/gamedev subreddit. Unity offers several approaches for resolving a reference to a GameObject in the scene. This is awesome! Freed from these string bindings, we can now work on our app with confidence instead of fear. We can do that by dragging and dropping the corresponding objects into these fields.Įven better, when we need to change our scene around later, Unity helps make the process as painless as possible, keeping the references hooked up when objects are renamed and moved around. The inspector also tells us that those dependencies have not been hooked up yet. Nice, now we see that our script relies on two things: the canvas and some text to display the number of children with. Whichever option we choose, here is how the script will appear when we attach it in the inspector after these changes: Using UnityEngine using UnityEngine.UI public class ShowNumberOfCanvasChildren : MonoBehaviour
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. Archives
December 2022
Categories |