Search Unity

How do i make an object appear then destroyed after an object is triggered

Discussion in 'Getting Started' started by puffyjoe7, Dec 29, 2022.

  1. puffyjoe7

    puffyjoe7

    Joined:
    Aug 9, 2020
    Posts:
    4
    trying to make a jumpscare
     
  2. AngryProgrammer

    AngryProgrammer

    Joined:
    Jun 4, 2019
    Posts:
    490
    1. If the object does not exist in the scene then you have to add it using Instantiate (https://docs.unity3d.com/ScriptReference/Object.Instantiate.html).
    2. To Instantiate object you need its Prefab (https://docs.unity3d.com/Manual/Prefabs.html).
    3. To destroy an object you use a Destroy method (https://docs.unity3d.com/ScriptReference/Object.Destroy.html).
    4. You probably want to keep the effect on screen for some time, so you need to put a timer in between (look to answer: https://answers.unity.com/questions/1493694/stop-game-for-1-second.html).
    5. You bundle everything together in one of the trigger methods (e.g. https://docs.unity3d.com/ScriptReference/Collider.OnTriggerEnter.html).
    Don't put everything together at once. Play with these elements to understand how it works. These are the basic elements that you will use many times.