Moving the units
Now that we have all the unit selection logic in place, we only need a couple more changes in the UnitSelectorComponent
class to have it ready to move the units where we want on the map. The Update
method, which is already defined in the UnitSelectorComponent
class, needs one more validation that we are going to add at the end of the method, as we can see in the following code block, which will be used to check whether the right mouse button was released, using KeyCode.Mouse1
:
private void Update() { … if (Input.GetKeyUp(KeyCode.Mouse1)) { Vector3 movePosition = GetMousePosition(); MoveSelectedUnits(movePosition); } }
Once we have the desired move position, which is where the player clicked on the map using the right mouse button, we can call the MoveSelectedUnits
method, which is defined next, as well as a new class variable named distanceBetweenUnits
:
private...