So there is my script :
var distance;
var target : Transform;
var lookAtDistance = 15.0;
var attackRange = 10.0;
var moveSpeed = 5.0;
var damping = 6.0;
var gameobject : GameObject;
var auidioclip : AudioClip;
private var isItAttacking = false;
function Update ()
{
distance = Vector3.Distance(target.position, transform.position);
if(distance < lookAtDistance)
{
isItAttacking = false;
audio.PlayOneShot(audioclip);
lookAt ();
}
if(distance > lookAtDistance)
{
renderer.material.color = Color.green;
}
if(distance < attackRange)
{
attack ();
}
if(isItAttacking)
{
Destroy(gameObject);
}
}
function lookAt ()
{
var rotation = Quaternion.LookRotation(target.position - transform.position);
transform.rotation = Quaternion.Slerp(transform.rotation, rotation, Time.deltaTime * damping);
}
function attack ()
{
isItAttacking = true;
Destroy(gameObject);
transform.Translate(Vector3.forward * moveSpeed *Time.deltaTime);
}
The problem is when i go close to the enemy , the sound start repeating many times …
But i want to hear the sound only 1 time in my game. I mean that i want to hear the sound normally once and then i want it to mute for ever. cant anyone please help me ?