- Home /
Audio clip not triggering
i have an enemy, and i want it so that when im a certain distance from the enemy it triggers a given sound file. given what i have so far, how should i go about making the audio trigger then stop once it has already been played? im very new to this so my minds all jumbled up here
var theEnemy : Transform;
var thePlayer : Transform;
public var soundWhenSeen : AudioClip;
private var hasBeenPlayed : boolean = false;
function Start () {
if (Vector3.Distance (theEnemy, thePlayer) <= 3);
{
(soundWhenSeen)
}
}
function Update ()
{
if(soundWhenSeen);
{
(hasBeenPlayed == true);
}
if(hasBeenPlayed == true);
{
(soundWhenSeen);
}
}
Answer by SubatomicHero · May 15, 2013 at 07:46 AM
Check out this scripting reference that play an audio file only once:
http://docs.unity3d.com/Documentation/ScriptReference/AudioSource.PlayOneShot.html
Your answer
Follow this Question
Related Questions
Can't get my sound to work.. 1 Answer
Playing a different audio clip after another has finished 1 Answer
Load Scene by audio clip 2 Answers
Get audio from device... -1 Answers
Help with sound clips [C#] 0 Answers