Different ways to create Audio clip

Here’s a method I used for the sounds. I basically ‘teleport’ the object off map, and then delay the destruction of the object by one second, giving it time to play the sound effect. Of course, there are problems with this approach and is possibly an even dirtier approach to the one Rick used in the lecture!

using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class CoinPickup : MonoBehaviour
{
    [SerializeField] AudioClip coinPickup;

    void OnTriggerEnter2D(Collider2D other) 
    {
        if(other.tag == "Player")
        {
            transform.position = Vector2.one * 9999f;
            GetComponent<AudioSource>().PlayOneShot(coinPickup);
            Destroy(gameObject,1f);
        }
    }

}

1 Like

Privacy & Terms