Quantcast
Channel: Questions in topic: "crash"
Viewing all articles
Browse latest Browse all 2383

Game crashes in loop with multiple instances of coroutine

$
0
0
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.

Viewing all articles
Browse latest Browse all 2383

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>