Guys please help me , i have a problem
the problem is
When i go to the assigned character and touches it, it spams the audio and lags everything whereas if i am away from him,it work fine
For example
IIII(is my character)
OOO(is the assigned character)
so when i am like
III OOO (it works fine)
nut when i am like
IIIOOO(it spams the audio and lags everything)
here’s my script
#pragma strict
var VoiceToSpeak : AudioClip;
var character : Transform;
var playAudio = true;
var Distance = 10;
var DelayOfSpeaking = 10;
function Update ()
{
var player : Vector3 = character.position;
var moveDirection : Vector3 = player - transform.position;
if (moveDirection.magnitude < Distance)
{
Play_Audio();
}
}
function Play_Audio()
{
if (playAudio == true);
{
playAudio = false;
GetComponent.<AudioSource>().Stop();
GetComponent.<AudioSource>().PlayOneShot(VoiceToSpeak);
print ("audio playing");
yield WaitForSeconds (DelayOfSpeaking);
playAudio = true;
}
}