Hey guys,
I’m currently working on a rhythm game where if an obstacle is destroyed it makes a clapping sound. However, for some reason the clapping audio doesn’t play. I know the audio works since it plays if I check the PlayOnAwake box and the Debug.Log goes through just fine. Despite this, the audio still doesn’t play when an obstacle is destroyed.
Here’s the script in question:
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class DestroyObject : MonoBehaviour {
ScoreSystem Score;
int ScoreFromHit;
public AudioSource source;
private void Start()
{
Score = FindObjectOfType<ScoreSystem>();
source = GetComponent<AudioSource>();
}
void OnTriggerEnter( Collider other )
{
if (other.gameObject.tag == "Perfect Hit")
{
source.Play();
Debug.Log("clap");
ScoreFromHit = 25;
Score.Scoring(ScoreFromHit);
Destroy(gameObject);
}
if (other.gameObject.tag == "Early Hit")
{
source.Play();
Debug.Log("clap");
ScoreFromHit = 10;
Score.Scoring(ScoreFromHit);
Destroy(gameObject);
}
if (other.gameObject.tag == "Late Hit")
{
source.Play();
Debug.Log("clap");
ScoreFromHit = 5;
Score.Scoring(ScoreFromHit);
Destroy(gameObject);
}
}
}
Any assistance is much appreciated. Thank you!