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

OnCollisionEnter2D() Instantiate Causing an Infinite Loop

$
0
0
Hey guys, I'm trying to Instantiate a new object after an object leaves the spawning zone. Here's is what I've got so far (This is attached to the spawning zone GO): void OnTriggerEnter2D(Collider2D col){ if(!outsideQuads.Contains(isHit)){ isInside = true; } } void OnTriggerExit2D(Collider2D col){ isInside = false; if(!outsideQuads.Contains(col.gameObject)){ outsideQuads.Add(col.gameObject); } } void Spawner(){ Instantiate(quads[Random.Range(0, quads.Length)], transform.position, Quaternion.identity); } And here is the script that's attached to the shapes: void Start(){ dqs = GameObject.FindGameObjectWithTag("DS_Holder"); } void OnCollisionEnter2D(){ if(!dqs.GetComponent().isInside){ Instantiate(quads[Random.Range(0, quads.Length)], transform.position, Quaternion.identity); } } But this causing the game to spawn multiple objects, without waiting for the object inside of the spawning zone to exit. (Causing an Infinite Loop that crashes Unity, see pic below) Any ideas? ![alt text][1] [1]: /storage/temp/29423-ifcrash.png

Viewing all articles
Browse latest Browse all 2383

Trending Articles



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