using UnityEngine;
public class UnitClick : MonoBehaviour
{
private Camera myCam;
public LayerMask clickable;
public LayerMask ground;
void Start()
{
myCam = Camera.main;
}
void Update()
{
if (Input.GetMouseButtonDown(0))
{
**Ray ray = myCam.ScreenPointToRay(Input.mousePosition);**
RaycastHit hit;
if (Physics.Raycast(ray, out hit, Mathf.Infinity, clickable))
{
if (Input.GetKey(KeyCode.LeftShift))
{
UnitSelections.Instance.ShiftClickSelect(hit.collider.gameObject);
}
else
{
UnitSelections.Instance.ClickSelect(hit.collider.gameObject);
}
}
else
{
if (!Input.GetKey(KeyCode.LeftShift))
{
UnitSelections.Instance.DeselectAll();
}
}
}
}
}
I killed more than half a day to find the source of the problem and did not find it...
I tried to rewrite a little and change the cameras to public ones and changed the raycast, but nothing helped...