This is supposed to repeat every second until the animation stops playing, but the sound repeats every frame! Here’s my code (in JS):
#pragma strict
var chopSound: AudioClip;
var isPlaying = false;
function AnimPlay () {
animation.Play();
while (animation.isPlaying){
yield WaitForSeconds(1);
audio.PlayOneShot(chopSound);
yield WaitForSeconds (1);
}
}
are you calling AnimPlay() from Update somewhere? can we see that code?
Yes, I am calling it through a different script with the SendMessage code. Here’s my other script:
#pragma strict
var Player: GameObject;
var Lumber: GameObject;
var Sapling: GameObject;
var Range: float = 5;
var ChopTimer: float = 5;
var InstantiateCount: float = 1;
var Colliders: Collider[];
function OnMouseOver () {
Colliders = Physics.OverlapSphere(transform.position, Range);
if (Input.GetMouseButton(0)){
for (var hit in Colliders){
if (!hit){
continue;
}
if (hit.transform.name == "First Person Controller"){
ChopTimer -= Time.deltaTime;
Player.gameObject.SendMessage("AnimPlay");
}
}
if (ChopTimer <= 0 && InstantiateCount == 1){
Destroy(transform.gameObject);
ChopTimer = 5;
InstantiateCount = 0;
Refill();
}
}
}
function Update () {
Debug.Log(ChopTimer);
}
function Refill () {
InstantiateCount = 1;
}
Thank you, I’ll try to figure it out from here!