Krebsey
Krebsey

Reputation: 29

Particle System not Initializing

I am trying to have a particle system instantiated right before my prefabed object is destroyed, and I can't find out what isn't working. I have play-on-awake checked.

    [SerializeField] ParticleSystem destruction;
if (destruction != null)
        {

            Debug.Log("this objects transform: " + this.transform);
            Instantiate(destruction, this.transform);
            
        }

        if (tag != "Wall")
        {
            Destroy(gameObject);
        }

Upvotes: 0

Views: 191

Answers (2)

Housheng-MSFT
Housheng-MSFT

Reputation: 762

The usage of Instantiate in Unity, this is a simple example

       //pass in d preset
    public GameObject explosion; // Explosion effect Prefab component  (an explosion animation)

      void OnExplode()
     {
       // Create a Quaternion with a random rotation angle
       // Quaternion.Euler Euler angles
       // Returns a rotation angle that rotates y degrees around the y axis, x degrees around the x axis, and z degrees around the z axis.
     Quaternion randomRotation = Quaternion.Euler(0f, 0f, Random.Range(0f, 360f));

     // Initialize the instance of explosion
     // Parameter 1: is the preset Parameter 2: The coordinates of the instantiated preset Parameter 3: The rotation angle of the instantiated preset
     Instantiate(explosion, transform.position, randomRotation);
    }

Thank you hope it can help you

Upvotes: 0

Krebsey
Krebsey

Reputation: 29

Using

Instantiate(destruction, this.transform.position, this.transform.rotation);

worked.

Upvotes: 1

Related Questions