I’m trying to play an audio source when a gameobject gets destroyed on collision. I have the Audio Source enabled, but Unity is giving me this error message:
“Can not play a disabled audio source
UnityEngine.AudioSource:Play()”
However, if I leave Play on Awake checked, it gives me this error message but plays the audio source once on startup, even though this isn’t at all what I want. Here’s my script.
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class RingPickup : MonoBehaviour {
public GameManager gm;
public AudioSource RingSound;
public bool ringDark;
// Use this for initialization
void Start () {
RingSound = GetComponent<AudioSource>();
gm = FindObjectOfType<GameManager>();
}
void OnTriggerEnter(Collider col)
{
if(col.tag == "Player")
{
Debug.Log("Play ring sound");
RingSound.Play();
if (ringDark)
gm.darkRings++;
if(!ringDark)
gm.rings++;
Destroy(gameObject);
}
}
}