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

Moving out of collision with trigger using while loop crashes Unity.

$
0
0
I'm trying to move a game object to the left until it is no longer touching a trigger using a while loop in the OnTriggerEnter2D function, but it crashes Unity. Here's my code: void OnTriggerEnter2D(Collider2D c) { if(c.gameObject.tag == "Player") { while(c.IsTouching(transform.GetComponent())) c.transform.Translate(new Vector2(-1f, 0)); } } Anyone know why?

Viewing all articles
Browse latest Browse all 2383

Trending Articles