Hey all,
I’m trying to make an object (with a box collider) interact with a click to exit out of a while loop using a Raycast. However, although I think I have all the components necessary to initiate it, nothing happens when I click on the object, and the while loop keeps looping. The snippet of code follows:
public IEnumerator Qone()
{
t.text = "A: 1";
while (i == 0)
{
Ray ray = Camera.main.ScreenPointToRay(Input.mousePosition);
RaycastHit hit;
if (Input.GetMouseButtonDown(0))
{
if (Physics.Raycast(ray, out hit))
{
if (hit.transform.name == "A")
{
Debug.Log("hit");
i = 1;
}
}
}
Debug.Log("F");
yield return null ;
}
i = 0;
StopAllCoroutines();
}