[Solved] Particle system not working as explosion [unity 2017]

Hi, I’m trying somethings on my game by my own like including a particle explosion when an enemy is destroyed.

I sucefully included the particle system on my game and it does show on the Hierarchy, but it seens to be invisible on the playspace.

Actually it only happens when I attach the position of the particle system to the enemy I destroyed. (i.e., on the Instantiate method if I only writhe (Instatiate (explosion)), it works fine, but the explosion will always appear on the same place. If I put Instantiate(explosion, transform.position, transform.rotation); [like this:]

public class Col : MonoBehaviour {
public GameObject explosion;
void OnCollisionEnter2D(Collision2D collider)
{
Instantiate(explosion, transform.position, transform.rotation);
GameObject.Destroy(gameObject);
GameObject.Destroy(collider.gameObject);

It appears on the hierarchy but not on the playscene (it stays invisible).

My Project file:

thank you

Hi,

Bit confused… just imported the package and it appears to be Block Breaker - but with some Laser Defender assets mixed in to.

There isn’t a playable scene to test against?


Updated Mon Sep 25 2017 17:29

Ok, I’ve fiddled around with it to get something doing something… here’s a screenshot of your issue;

image

Your particles are in fact there, but you have them rotated in such a way that they are going “in” to the screen as it were. As it’s a 2D game, you can’t see them. If you change from 2D to 3D and rotate around the ship, you should be able to see the above.

Your prefab has a rotation of -90 on the X, however, in code you are setting the rotation to that of the game object it is spawning from in Col.cs;

    Instantiate(explosion, transform.position, transform.rotation)

You could either change your code to use the rotation of the prefab that you have referenced in (explosion) using this;

    Instantiate(explosion, transform.position, explosion.transform.rotation)

Or, consider changing the rotation of the particle system as you instantiate it, or after.

You can use this to help debug;

    Debug.Log("Enemy Position : " + transform.rotation.ToString());
    GameObject exp = Instantiate(explosion, transform.position, transform.rotation) as GameObject;
    Debug.Log("Particle Position : " + exp.transform.rotation.ToString());

I also modified the particle effects dramatically ensuring I would be able to see something, properties as follows;

image

Wow, that was tricky. Thank you very much

1 Like

You’re welcome Luiz :slight_smile:

Privacy & Terms