I have a GameController script which I am using to manage most of my game interactions. I want to be able to click and select units on the scene and I was wondering what the best way to do this is without listening for the mouse event on the unit game object.
Since I also want to be able to click terrain and other objects in the scene, how would I go about getting the 'type' of object clicked? I am currently using the following code:
if(Input.GetButtonDown("Fire1")){
Ray ray = Camera.main.ScreenPointToRay(Input.mousePosition);
RaycastHit hit;
if(Physics.Raycast(ray, out hit, 1000F)){
}
}
But I'm not sure how I'd detect what kind of object was clicked. For example if I clicked a unit, I'd want to run my selectUnit() method, but if I clicked the surface plane, I'd perhaps want to run the moveCameraToPoint() method instead.