so i have 4 different game objects on the screen each with their own script (example below with respective changes in each to identify them) but when i start my project and click on one of them all of them are hit by the Raycast is that what is supposed to happen? as ideally i would like to identify all 4 separately
void Start () { }
void Update () {
if (Input.GetMouseButtonDown(0))
{
Ray ray = Camera.main.ScreenPointToRay(Input.mousePosition);
RaycastHit hit;
if (Physics.Raycast(ray, out hit))
{
if (hit.transform.gameObject)
{
PlayerPrefs.SetFloat("obj", 2);
Debug.Log("This is object2");
}
else
{
Debug.Log("No object");
}
}
}
}
}