The question was asked many times. The problem is: when running this code (attached to CharacterController)
var snd : AudioClip;
var played : boolean;
function OnControllerColliderHit(hit : ControllerColliderHit)
{
if(!played)
{
audio.PlayOneShot(snd);
played = true;
}
}
→ you’re able to play collision sound just once. What if I collide again? No sound will be played (need to reset played flag). I tried OnCollisionExit() to reset the flag (played = false) but it doesn’t work for CharacterController. Another possible solution - reset played flag depending on time:
function Update()
{
timeUntilNextPlayback += Time.deltaTme;
if(timeUntilNextPlayback > SOME_AMMOUNT_OF_TIME)
played = false;
}
→ but it’s not the best possible solution.
Does anyone no way to acomplish this task OR check when collision exits with my CharacterController? (I must not Destroy() any object)