If I select some GameObject
in the Unity, e.g. recently added TextMeshProUGUI
inside the Canvas
, where can I find out the type of selected game object?
In Inspector window, same as in Properties window (shown using context menu on the game object in Hierarcy window), I can see the name, tag, layout, etc. But where is the type?
I need to know the type to reference the game object in the code:
using TMPro;
using UnityEngine;
public class Foo: MonoBehaviour
{
public TextMeshProUGUI bar;
...
public SomeMethod() => bar.text = "bla";
}
I've found this topic which is rather confusing than helpful. Sure, all of game objects are inherited from GameObject
, but to access bar.text
I will need to know its type anyway.
From other point of view, I can look for components in Inspector and always use bar.GetComponent<XYZ>()
, but similarly, XYZ
is not shown in Inspector, I can see "TextMeshPro - Text (UI)" caption, which is not really TMPro.TextMeshProUGUI
type I need to use in the code. So I have come to another question, how to get component type... Great isn't it?
I am likely missing something obvious. Am I the first asking this question?