Hi, I’m making a small racing game and I want a sound to play whenever I pass a checkpoint. While the checkpoint works as intended, the audio doesn’t work. Here’s my code:
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
using UnityEngine.SceneManagement;
public class PlayerControl : MonoBehaviour
{
public AudioClip Check;
AudioSource sonido;
void Start()
{
sonido = GetComponent<AudioSource>();
}
void OnTriggerEnter(Collider other)
{
if(other.gameObject.tag == "Checkpoint"){
tiempo+=5;
sonido.PlayOneShot(Check);
Destroy (other.gameObject);
MostrarTexto();
}
}
I’ve heard some people say that the reason the audio won’t play is because the object gets destroyed. However, I’ve tried removing the Destroy function and still nothing. What am I doing wrong?