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

Unity editor is crashing OnTriggerEnter2D

$
0
0
Hi, just trying to make a simple platformer where the next platform instantiates based on an array of locations set from the original platform's location. The original platform is a prefab containing the main platform with a collider so that the player can bounce off, a range of empty transforms to be used as a location to instantiate the next platform, and an empty that holds the box collider 2D to trigger the instantiation. The code is in that empty public void OnTriggerEnter2D(Collider2D collider) { if (collider.gameObject.tag == "Player") { Debug.Log("Hit"); int n = Random.Range(0, spawnPoints.Length); GameObject newPlat = Instantiate(platform, spawnPoints[n].transform, platform); Destroy(gameObject,2f); } } "spawnPoints" is the array of transforms for possible positions for the next platform to be instantiated. I'm pretty novice at coding, but I didn't expect my code to outright crash Unity; is there anything that I'm doing here that might overwhelm the editor? Thanks for any help, and sorry if I didn't post enough info

Viewing all articles
Browse latest Browse all 2383

Trending Articles