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.
That’s a very good question. Both those options work for me. Are you referencing the correct Image type? You should have using UnityEngine.UI; at the top. I know there are some other namespaces that also have Image types, like Microsoft.Unity.VisualStudio.Editor for instance
Yup like @bixarrio said both methods should work, what exactly doesn’t work?
Disabling the game object will disable all components, disabling the image only disables the image component, if that’s the only component on the object then both do basically the same thing
But I have a follow up question: Like I said I tried to have the same structure we made for the GridSystemVisual and GridSystemVisualSingle which is basically the same starting situation. There we handled the logic for showing and hiding in the prefab-initializing-script (GridSystemVisual) while the script on the prefab (GridSystemVisualSingle) only has the methods Show() and Hide().
For the ActionButtonUI we handle the show/hide logic on the Prefab-script directly.
Is there a specific reason for doing it differently this time? There was a similar question with the answer that it’s mostly preference, but now we have both approaches in the same project.
For the Action button, the visual show/hide depends on the underlying BaseAction which the button has a reference to, so it makes sense for the button to use the info it already has in order to decide its state.
Whereas on the Grid Visual, each individual Grid Visual Single doesn’t have any extra data, it’s just a dumb visual, it does not know what is the selected action, what is the selected unit, etc. So it makes sense for an external script that does have that information to just tell it what to do.
But as usual there’s a million ways to solve the same problem, so making the UnitActionSystemUI decide which button to show or hide also works just fine.