Thursday, 28 August 2014

Unit Selection (week #10)

for the selection of characters in my turn based strategy game I have used a raycast utilizing camera.ScreenPointToRay to the mouse position when the left mouse button is pressed. this ray then accesses the gameobjects that are carrying the player script allowing the public function "Selected."
On the player script there are numerous variables which are attatched but only a few are effected by the selected function, these include the public boolean selected which will be utilized to perform actions when the object's selected status is true or false and amountSelected integer which will be used to cap the amount of selected units.
when the selected function has been activated the script will then check the status of the selected and amountSelected variables, if selected is false and the amountSelected equals 0 then the selected variable becomes true and the amountselected equals 1 to prevent any more units from being selected at that time. This also instantiates a green ring similar to some real time strategy games like Starcraft and Warcraft at the position of the selected unit to provide some visual feedback letting the player know that the object has been selected.
if you are working on a project and you need some way of interacting with the world using your mouse cursor position I recommend looking at camera.ScreenPointToRay in the Unity Scripting API linked here :

Next week I plan on adding Health bars on top of units' heads which follow their position. if you have any feedback please let me know.

No comments:

Post a Comment