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

Unity crashes after I destroy a gameobject

$
0
0
So I wrote what I thought would be a simple script for destroying an object after doing something specific, but it crashes my game? `public class DestroyThis : MonoBehaviour { public bool hasTalked; void Start() { hasTalked = false; } private void OnTriggerEnter2D(Collider2D player) { while (hasTalked == true) { if (player.gameObject.tag == "Player") { DestroyGameObject(); } } } void DestroyGameObject() { Destroy(gameObject); } }` hasTalked becomes true once you talk to an npc, but once it does and the player triggers the object, the game literally freezes and there's no way to escape other than ending unity through Task Manager. What is the problem??

Viewing all articles
Browse latest Browse all 2383

Trending Articles



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