Hi there. I just started out learning unity so please bear with me:
I have a two cubes in my scene. One cube is a floor and the other is a small cube object above the floor.
The small cube object is a rigid body, uses gravity and the material is bouncy.
I want to play a sound when the cube falls and collides with the floor. So i coded this:
using UnityEngine;
using System.Collections;
public class boxCollision : MonoBehaviour {
public AudioClip collisionSound;
void OnCollisionEnter(Collision theCollision){
if(theCollision.gameObject.name == "Floor"){
AudioSource.PlayClipAtPoint(collisionSound, transform.position);
}
}
}
now when i attach a sound file, and play the game, the cube drops and the sound is played, but when it bounces back up and hit the floor again, the sound is not play.
Can you explain me why it is not playing the sound again?