- Home /
Best way to check object selection
Heya
Consider this. I have these objects which the player can select in-game. When an object is selected it will constantly move to the mouse position. Right now I am using a "Selection Script" with a "OnMouseDown" function on each object. This will send information to a GameController object and set a "isSelected" bool to true and set a GameObject variable "SelectedObject" to the object clicked.
The GameController has a controller script which moves the selected object to the mouse position through an update function. I've got the mechanic working as I want. So far so good.
But it has just occurred to me that I could check if an object is clicked in the Update in the GameController script and set the "SelectedObject" that way instead of the "OnMouseDown" on each object. This will spare me having the "Selection Script" on each object in game.
(I could also run the check selection in an update function on each object)
The question is. What is the best way around this of the three possibilities? And if there is a better way, please do tell.
Thanks in advance.