while (select)
{
print("looping");
//choose a unit
if (mouse)
{
print("mouse");
if (Physics.Raycast(Camera.main.ScreenPointToRay(Input.mousePosition), out RaycastHit rayHit, Mathf.Infinity, LayerMask.GetMask("unitLayer")))
{
print("raycast");
if (!otherUnits.Contains(rayHit.collider.GetComponent()))
{
print("not an option");
continue;
}
Unit target = rayHit.collider.GetComponent();
closeCombats.Add(new Unit[] { initiator, target });
select = false;
}
}
yield return null;
}
My game is crashing when I click the mouse (which controls the mouse variable).
This code is inside a coroutine and only crashes the game if two instances of the coroutine are running. When there is only one it works fine.
"looping" prints but "mouse" does not.
I have tried to work it out but I must not understand coroutines enough.
↧