Quantcast
Channel: Questions in topic: "error"
Viewing all articles
Browse latest Browse all 7934

Collision returning an error

$
0
0
Hi there, I have come across an problem that I can't solve. This is part of my crate's script. When in collides, I want it to spawn a coin from the pool. No errors show up in the console until the "rocket" (basically a bullet) collides with the box. I also have a rocket pool and all the rockets inside the hierarchy are clones of the original one. This is a 2D platformer/run'n'gun game. void OnCollisionEnter2D(Collision2D collision) { //Prepare coin spawn from pool and set to crate position GameObject obj = CoinPooling.current.GetPooledObject(); if (obj == null) return; obj.transform.position = transform.position; if(collision.gameObject.tag == "Player") //If my player hits the crate spawn coin and set crate inactive { obj.SetActive(true); gameObject.SetActive(false); } else if (collision.gameObject.tag == "Rocket")//Error seems to be here. //Spawn coin, deactivate crate, activate explosion particle system (attached to rocket), then deactivate rocket. { obj.SetActive(true); gameObject.SetActive(false); collision.transform.FindChild("Explosion").gameObject.SetActive(true); //Trigger explosion collision.gameObject.SetActive(false); } } Do you have any idea why the error message is : Object Reference Not Set To An Instance Of An Object ? Thank you in advance.

Viewing all articles
Browse latest Browse all 7934

Trending Articles



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