Unity Turn Based Strategy Course - Generic Take Action

I’m using this course as a base to create a city building. I have created a class named BuildAction based upon the BaseAction.

What I’m not sure about, is when should I show the “ghost” for the selected building.
I’ve added this non elegant solution:

if (Input.GetMouseButtonDown(0))
        {
.....
  if (selectedAction.IsBuildAction())
            {
                selectedAction.ShowPreaction(ClearBusy);
            }
....
}

I’m using this in order to know if the action is a building action, or a unit action.
But the selectedAction.TakeAction(mouseGridPosition, ClearBusy); should still confirm the construction of the building.
What would be the best way to Implement some onClick confirmation? Should the action send a response saying the ghost is in place to confirm construction? else show ghost?.

I know this question is not the objetive of the course, but i believe is somewhat related.
Thanks.

I would show the ghost as soon as the SelectedAction is selected in the UI, that’s the first “click”, to get the ghost activated. The Selected Action should then move the ghost to the current GridPosition of the mouse until either a different action is selected (remove Ghost) or the mouse button is clicked, at which point then you would call selectedAction.TakeAction(mouseGridPosition, ClearBusy).

2 Likes

Thank you for your quick response.
What you suggested definitly makes sense. I’m just not sure how to know when was the action called for the first time, I’m going to need some kind of flag inside the BuildAction, like isGhostShowing, this ways i can know when was clicked for the second time to confirm the build.
That aside, how can i know when another action has been selected? have in mind, that, at such time, the selectedAction would have changed, hence i wouldn’t be able to call something like selectedAction.HideGhost().
Maybe using something like the ClearBussy delegate which I’m not very familiar with.

That might be a bit trickier…
You could have the BuildAction subscribe to the OnSelectedActionChange method… The handler would then check to see if the UnitActionSystem.GetSelectedAction() was equal to this. If it’s not this then call HideGhost().

3 Likes

Privacy & Terms