Hi,
i start learning unity but i have a problem.
i have 2 different objects in my scene a Cube and a Sphere with 2 different scripts to detect is the object has been clicked.
but when i click on the cube also the sphere gets hitted?
the cube code :
void Update()
{
if (Input.GetMouseButtonDown(0))
{
Ray ray = Camera.main.ScreenPointToRay(Input.mousePosition);
RaycastHit hit;
if (Physics.Raycast(ray, out hit, 100))
{
Debug.Log("Clicked on Cube");
}
}
}
sphere code :
void Update()
{
if (Input.GetMouseButtonDown(0))
{
Ray ray = Camera.main.ScreenPointToRay(Input.mousePosition);
RaycastHit hit;
if (Physics.Raycast(ray, out hit, 100))
{
Debug.Log("Clicked on Sphere");
}
}
}
i know its the same code but why do they get triggered both?
thanks in advance,