Selecting Unit and Moving in one click

When I click on a unit that wasn’t selected (on his torso) and his torso is positioned in front of a grid square that is available, the unit will become selected and move to the square behind the torso with just one click. Did I miss the fix for this or has it not been covered yet? Thanks

I think you missed something. There is no fix because it never happened. What we had, though, was that you couldn’t click through the unselected unit to a valid cell behind it, and we fixed that. Show your UnitActionSystem and we can look to find the issue.





In your HandleSelectedAction you are using Input.GetMouseButton(0). This should be Input.GetMouseButtonDown(0).

Input.GetMouseButtonDown(0) returns true only in the frame that it went down. Input.GetMouseButton(0) returns true in every frame that the button is held down. So, what’s happening is that you click and the TryHandleUnitSelection() finds a unit and skips the rest of the update. On the next frame, TryhandleUnitSelection() does not do the raycast because in this frame the button wasn’t pressed. So, it returns false and the code goes on to HandleSelectedAction(). In here the button is still pressed (event though it was pressed in the previous frame) so this code runs, too.

That fixed it! Thanks!

For future code pastes, please paste in the text of the script rather than a screenshot.

1 Like

This topic was automatically closed 24 hours after the last reply. New replies are no longer allowed.

Privacy & Terms