Search Unity

how do i make a sound play after i destroy and object

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

  1. puffyjoe7

    puffyjoe7

    Joined:
    Aug 9, 2020
    Posts:
    4
    as the title say and yes i still suck at coding

    Code (CSharp):
    1. using UnityEngine;
    2. using System.Collections;
    3.  
    4. public class WhenPressOrbGone : MonoBehaviour
    5. {
    6.     public GameObject objToDestroy;
    7.     public GameObject effect;
    8.  
    9.     // Use this for initialization
    10.     void OnTriggerEnter(Collider other)
    11.     {
    12.         if(other.gameObject.tag == "Player")
    13.             Instantiate(effect, objToDestroy.transform.position, objToDestroy.transform.rotation);
    14.             Destroy(objToDestroy);
    15.     }
    16. }
     
  2. AngryProgrammer

    AngryProgrammer

    Joined:
    Jun 4, 2019
    Posts:
    490