Hey so I have a car that is grounded but occasionally goes in the air. I want a landing sound to play only when it hits the ground after being in the air. I’ve only been able to find scripts pertaining to Character Controllers using isGrounded and not GameObjects. The script I have now obviously doesn’t work because if the car is driving on the ground, it constantly wants to play the landing sound. But I can’t figure how to prevent that. Any help would be great!
{
public AudioClip[] carLandingsArray;
AudioSource audio;
public bool isGrounded;
void Start()
{
audio = GetComponent<AudioSource> ();
isGrounded = true;
}
void Update()
{
if (isGrounded)
{
audio.PlayOneShot (carLandingsArray [Random.Range (0, 1)]);
}
}
}