Okay i'll try to explain what i'm doing first because maybe i'm approaching this the wrong way.
I have a function called playSound() which is itself called by either an animation event, through some action by the player (pressing a button for example), or - not yet implemented - called in an object's Start() function.
The playSound() function in turn is responsible for playing a sound and calling another function, on another script, called playAnim(). This function cycles through the textures of the GUITexture on the object it is attached to, and also hides the guiTexture if the player is not within range.
It works fine at the moment because the animation events are fired once every so often. However, with player input or the Start() function, I need the sound effect to keep playing and the guiTexture to keep animating. Moving them into Update() functions hasn't helped, either because the music stutters (I can add an if statement to fix that) or the guiTexture is replaced too rapidly.
My code is becoming a bit unruly now so I am trying to keep everything in three separate functions: sound, animation, and what will be particle systems. I want to keep my existing animation script which works with one time events, so i'm now trying to add a boolean that reruns the function if it is set to loop. From what i've read, this is called recursion, but I can't get the syntax right. I've also read about InvokeRepeating and CoRoutines but i'm not sure how i'd use them here. I just need the function to repeat, not delay. I tried something along the lines of:
function PlayAnim() {
// loop through guiTextures here
// check if this animation has been set to loop
if(isLooped){
PlayAnim();
} else {
guiTexture.enabled = false;
}
}
But I get an error "..type could not be resolved because of a cycle. Explicitly declare the type of either one to break the cycle." Here's a diagram to illustrate what i've discussed:
Animation Event Player input Start function
|___________________ | ________________|
|_ _ _ |_ _ _ _|
| |
| playSound() |<----
|_ _ _ _ _ _ _ _ | |
__________| | |
| | |
_ _ _ _ |_ _ _ _ | _ _ _ _ _ |
| | | | |
| playAnim()| | Particle Effect | |
|_ _ _ _ _ _| |_ _ _ _ _ _ _ _ _| |
| | |
|_______isLooped?_____|_______|