I have this code, calling a function when an object is clicked:
if (Input.GetMouseButtonDown(0))
{
Ray ray = cam.ScreenPointToRay(Input.mousePosition);
RaycastHit hit;
if (Physics.Raycast(ray, out hit))
{
Debug.Log("Hit " + hit.collider.name);
this.clicked();
}
}
Function Clicked:
void clicked()
{
Debug.Log("Clicked " + gameObject.name);
if (controller.selectedColor == i)
{
timeTracker = Random.Range(3.0f, controller.timeMaximum + 1.0f);
time = 0.0f;
i = 0;
activateRightColor();
changed = false;
} else
{
time -= 1.0f;
}
}
I have 3 objects that are clickable, and each one of them has 3 childs.
When I click on one object but the others have the same condition the function Clicked is called for all of them.
Why is it being called on all objects?