Just use a raycast from your cursor coordinates. Like so:
void Update () {
if(Input.GetButtonDown("Fire1")) {
Ray ray = Camera.main.ScreenPointToRay(Input.mousePosition);
RaycastHit hit;
if(Physics.Raycast(ray, hit, 100)) {
if (hit.collider.gameObject.tag == "enemy") {
selectedTarget = hit.collider.gameObject;
}
}
}
}
You may need to fit it into your code a bit better as you see fit.
Hope that helps, Klep
↧