Okay so basically I have a game where stuff drops onto the ground/people. When it hits them, I want the game to make a “splat” sound. But for whatever reason, I cannot get any audio to play during the collision. I have checked to make sure the sound is 2D, the AudioClip is assigned via the inspector, the volume is all the way up, and that there is an audio listener. I have background music in the game so audio is definitely working. The rest of the collision is also working.
I don’t get any console errors either.
I’m completely stumped, I’ve tried both AudioSource.Play and AudioSource.PlayOneShot, neither work.
Here’s my code:
public class DestroyOnImpact : MonoBehaviour
{
public int score;
public Transform Self;
public GameObject Splat;
public AudioClip SplatSound;
AudioSource Audio;
private void Awake()
{
Audio = GetComponent<AudioSource>();
}
void OnCollisionEnter2D(Collision2D collision)
{
if (collision.gameObject.tag == "Ground" || collision.gameObject.tag == "StunnedEnemy")
{
Audio.PlayOneShot(SplatSound, 1); //Doesn't work?!?!?!?!
Instantiate(Splat, transform.position, transform.rotation);
Destroy(gameObject);
}
if (collision.gameObject.tag == "WalkingEnemy")
{
Audio.PlayOneShot(SplatSound, 1); //Doesn't work?!?!?!?!
GameObject.Find("Player").GetComponent<PlayerProperties>().Score += 10;
Instantiate(Splat, transform.position, transform.rotation);
Destroy(gameObject);
}
}
}