RTS basic selection issues

Please use code tags when posting code on the forums. You can look at this thread for how to do that: Using code tags properly

I think the simplest solution would be to use the IPointerDown (/Click) handler interface. That would intercept the event for the unique game object. In the method, you can set the projector active/not.

However, for some additional info, to answer the question about “choosing the raycast hit game object”, what you could keep in mind is that you could use GetComponent to get a script on the ‘hit’ game object. Using that variable, you could call a method on the script to do your activate/de-activate.

One other thing that came to mind, was that since your raycasting also depended on the MouseButtonDown, you could have moved the raycasting portion of code within a block to execute, only if GetMouseButtonDown(0) was true, thus eliminating unnecessary calls.

Also, you could use this code in place of what you have:

projector.SetActive(!projector.activeSelf);

However, if your code is easier to understand, just keep it… except that you should use ‘false’ instead of ‘!true’, as it’s a bit more straightforward. :slight_smile:

I hope that helps…

1 Like