Right, i have an audioclip that plays when an animation is playing, which is triggered by a collision. Im using the !audio.isPlaying script so it on plays once while the animation is running. However, it then plays again once the animation finishes, i do not want this to happen. I;ve tried a few ways to get round it but no success.
Any ideas?
oh yeah here’s the code so far:
var lift : AudioClip;
function Start(){
animation.Stop(“downLift”);
}
function OnCollisionEnter (collision:Collision){
if (collision.gameObject.tag==“oshi”){
yield new WaitForSeconds (1);
animation.Play(“downLift”);
}
if(!audio.isPlaying){
audio.Play();
}
}
Nah, that dont work either. The sound is played when it collides with an object that acts as a lift down to a level. But because of the gravity, the character tends to jump up a bit every now and then, consiquently re-colliding with it causing the audio to be played again.
Realy i could do with the sound to be told to play just the once, or for the collider to turn off some how, when the animation is running.
I tend to do things in a strange kind of way, but what if you had another game object with the sound on it, and on collision, it becomes active ( have it Inactive on Awake). that way repeat collisions are going to make an object that is already active, active.
Or, have another trigger zone that repesents your lift, but its bigger than just the floor (ie the size of the lift room itself) that way your going to stay in that area and not rectrigger everytime like it does now. You could look at OnTriggerStay for that…
Im pretty sure the trigger functions in unity automatically work if theGO is tagged"Player", and that triggers will work better than collisions for your purposes…But thats one guys opinion.