I am trying to set a variable equal to the text in a label that represents the selected item in a dropdown in order to change what the mouse buttons do based on the dropdown, but I can’t figure out how to access the text in the label. Any help would be appreciated, because I haven’t found anything online that helps and am now completely stuck.
Please post code as text and put it in code tags.
Definitely switch to using UI Toolkit, not the legacy gameobject-based UGUI. This Text class and TextCore namespaces aren’t even in the manual anymore.
GameObject.Find(string) is what everyone will tell you to stay away from as well. It’s slow and brittle and things will break if you have the same label of the same name twice, or you rename the label in the scene. Just mark your selected label with [SerializeField] and assign the Text reference in the Inspector and you have it right there in your code, neither Find nor GetComponent needed.
That said … you may have simply confused yourself naming a GameObject selectedLabel but the Text that represents the label is called selected, and then you also have a method named Selected().
Try Debug.Log(selected.text)
… that’s your label’s text, quite simply.