- Home /
Emit particles on CollisionEnter2D works on one collision, not the other?
Hey guys, can somebody help me out with a C# issue I am having. I am currently using Unity 2d and hit a road block that has me completely stumped.
I basically have a shooting cannon, this cannon shoots a sprite with a kinematic rigidbody 2d. This projectile has a script attached in which it is destroyed over time, as well as destroyed when it hits a certain tag. When it hits a certain tag/collides with it, it is supposed to instantiate a particle explosion as such:
void OnTriggerEnter2D(Collider2D other){
if (other.tag == "Wall") {
Instantiate (CannonSplosion, other.transform.position, other.transform.rotation);
Destroy (this.gameObject);
}
if (other.tag == "Player") {
Instantiate (CannonSplosion, other.transform.position, other.transform.rotation);
Destroy (this.gameObject);
}
}
So... here is the weird thing. When this instantiated clone collides with my player, it plays the particle explosion and gets destroyed. When it hits my "walls", which basically are ground tiles created through the new Unity tile map, it gets destroyed, but doesn't play the particle explosion. I've been going crazy over this... lol Thank you in advance.
The attached picture shows the the instance when my projectile hit both my player and the above wall, but only one instance plays the particle explosion?
Below you can see the second my shot projectile hits the player and wall, it only plays the yellow particle explosion when it hits the player?
Answer by Paratrooper82 · Feb 15, 2018 at 02:58 AM
Here I am answering my own Question.
The fix was changing it from other.transform.position TO transform.position, within the tag "Wall" IF statement.
Your answer
Follow this Question
Related Questions
Distribute terrain in zones 3 Answers
Multiple Cars not working 1 Answer
GUIText Instantiation and Update the Instantiated Text. C# 1 Answer
How to spawn gameobject from host to all clients 1 Answer
Destroying childs and Instantiate [C#] 0 Answers