- Home /
PlayOneShot won't work.
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?
The only reason I can see is that Check
is not assigned. Have you dragged an audio clip to it in the Inspector?
Answer by TheTrueDuck · Jun 01 at 03:25 PM
Did you put an AudioSource on the gameobject that has the PlayerControl script? PlayerControl is only looking for audiosources on the same gameobject. Otherwise are you sure that the other parts of the function are being called like MostrarTexto();? It could be that your sound simply never gets triggered, if that's the case you may want to check the colliders involved or the tags on them. Otherwise, the AudioSource itself could be mute or have a volume of zero.
Your answer
Follow this Question
Related Questions
Playing many audioclips with PlayOneShot causes all sound to cut out. 0 Answers
Sound wont play when triggered (javascript) 1 Answer
Why PlayOneShot is not working? C# 1 Answer
WWW Audio and PlayOneShot: Playing the same AudioClip Twice Cuts off First Instance 1 Answer
How to fix my reload sound? 0 Answers