Play sound on collision doesnt actually play it
Everything seems fine, no errors pop up but this script doesn't seem to work
public AudioClip[] pickUpSound;
void PlaySound(int clip)
{
GetComponent<AudioSource>().clip = pickUpSound[clip];
GetComponent<AudioSource>().Play();
}
void OnTriggerEnter(Collider other)
{
if (other.gameObject.CompareTag("Player"))
{
PlaySound(0);
}
}
Can someone tell me what am I missing?
Put a Debug.Log inside your if statement, so you can check if it is detecting collisions.
I have tried your script its works perfectly fine. Check if the object you have attached the script contains the AudioSource component. Add debugs to check if the function is called.
Are you sure that the problem is that the sound is not playing? 99% of questions asked like this are caused by the collision not being detected, which, in turn, is almost always because you haven't got colliders/rigidbodies set up correctly.
Your answer
Follow this Question
Related Questions
Coroutine on collision 1 Answer
Sound on collision. 1 Answer
Making a group of cubes collapse 1 Answer
Problem with collision 1 Answer