I’m trying to play an audio clip whenever the player collides with the object. Everything else in the code works fine except for the fact that the audio doesn’t play. I have an audio source attached to the object and the following code that is in charge of playing the effects, adding values to the score, etc.
public class GemPickup : MonoBehaviour
{
public int value;
public GameObject pickupEffect;
public AudioSource pickupSound;
// Start is called before the first frame update
void Start()
{
pickupSound = GetComponent<AudioSource>();
}
private void OnTriggerEnter(Collider other) {
if(other.tag == "Player") {
FindObjectOfType<GameManager>().AddGem(value);
Instantiate(pickupEffect, transform.position, transform.rotation);
pickupSound.Play();
Destroy(gameObject);
}
}
}