Hello,
i have some trouble understanding why i can’t get “Selected”-object as an Image-type and set image.enabled to true or false like we did in the GridSystemVisualSingle.
We got the button of type Button by draging the ActionButtonUI into the SerializedField in the Inspector so we could add the Listener to the onClick-Event.
We could reference the TextMeshProUGUI Component by draging the “Text”-childObject to the Inspector and then directly set the text.
[SerializeField] private TextMeshProUGUI textMeshPro;
{
textMeshPro.GetComponent<TextMeshProUGUI>().text = baseAction.GetActionName().ToUpper();
}
It is also possible to get a reference of type “GameObject”, then get the Component “TextMeshProUGUI” and then set the text.
[SerializeField] private GameObject textGameObject;
{
textGameObject.GetComponent<TextMeshProUGUI>().text = baseAction.GetActionName().ToUpper();
}
So why can’t i reference the Image Component directly and disable it?
[SerializeField] private Image selectedImage;
public void HideSelectedImage(){
selectedImage.enabled = false;}
Even when i have the GameObject reference i can’t get the Image-component and disable it.
[SerializeField] private GameObject selectedGameObject;
public void HideSelectedImage(){
selectedGameObject.GetComponent<Image>().enabled = false;}
I know that when I have the GameObject-reference I can call the SetActive()-methode, but shouldn’t my initial solution work aswell?