I’m working on a 2D 8-ball pool game. In my game, each pool ball has a AudioSource attached. This AudioSource plays a hit sound with a random pitch every time it collides with another ball. However, as far as I can tell, Unity is only playing one sound at a time. I want sounds to overlap each other rather than play in rapid succession. Here’s my code:
public AudioClip ballHit;
public float audioSpeedModifier;
public AudioClip ballHit;
Rigidbody2D rBody;
AudioSource audioSource;
void OnCollisionEnter2D(Collision2D col){
if (col.gameObject.tag == "Ball" || col.gameObject.tag == "CueBall"){
audioSource.clip = ballHit;
audioSource.volume = rBody.velocity.magnitude * audioSpeedModifier;
float random = Random.Range (0.7f , 1.3f);
//Debug.Log (random);
audioSource.pitch = random;
audioSource.Play ();
}
}
Thanks.