Search Unity

  1. Megacity Metro Demo now available. Download now.
    Dismiss Notice
  2. Unity support for visionOS is now available. Learn more in our blog post.
    Dismiss Notice

Particles Effect not showing

Discussion in 'Getting Started' started by isaako, Nov 25, 2016.

  1. isaako

    isaako

    Joined:
    Nov 25, 2016
    Posts:
    15
    Hello everyone,

    I have a cube that when it gets hit by another object it disappears and the particles effects show up. It's working fine now, but I don't like that the particles appear automatically at the beginning of the game, so I unchecked the "Play on awake" box in the Inspector, and now the particles don't show neither in the beginning nor when the cube gets destroyed. If I check the "Play on awake" again they show at the beginning and when the cube gets destroyed, how can I make them appear just when the cube gets destroyed?

    This is my code for the box
    ---------------------------------------------------------------------------------------
    using UnityEngine;
    using System.Collections;

    public class BoxDestruction : MonoBehaviour {

    public GameObject BoxParticle;

    void OnCollisionEnter ()
    {
    Instantiate (BoxParticle, transform.position, Quaternion.identity);
    Destroy(gameObject);
    }
    }
    ---------------------------------------------------------------------------------------------

    Thanks in advance,
     
  2. JoeStrout

    JoeStrout

    Joined:
    Jan 14, 2011
    Posts:
    9,859
    You've got your particle effect as an object in the scene (i.e., it's in the Hierarchy tab in the Unity editor). It's part of the scene and it plays if you tell it to (by checking "Play on awake"). Then you instantiate a copy of it, and that plays if it's set to. All working as expected.

    There are several options here:
    1. Deactivate the object in the scene, and call SetActive on the new instance when you instantiate it.
    2. Uncheck Play On Awake, and call Play on the new instance particle system after you instantiate it.
    3. Turn the particle system prototype into a prefab, and delete it from the scene. So it exists only in the project (and only new instances exist in the scene).
    The third option is the standard solution.
     
  3. isaako

    isaako

    Joined:
    Nov 25, 2016
    Posts:
    15
    Thanks! It works perfectly
     
    JoeStrout likes this.