This question was
closed Apr 02, 2016 at 05:58 PM by
Slonika for the following reason:
The question is answered, right answer was accepted
Question by
Slonika · Apr 01, 2016 at 01:09 PM ·
coroutineparametersstopcoroutine
Get IEnumerator parameters with StopCoroutine
Hi. Is it possible with StopCoroutine (or smth else to stop IEnumerator) to get parameters, that was passed to IEnumerator?
IEnumerator current_speech;
void LoadLine(DialogObject.Node node) //get called from another script
{
/*
code code code
*/
current_speech = Speech(node);
StartCoroutine(current_speech);
}
IEnumerator Speech(DialogObject.Node node)
{
yield return new WaitForSeconds(node.voice.length);
Next(node);
}
void Skip()
{
if (current_speech != null)
StopCoroutine(current_speech);
Next(node); //node - is what i want to get from current_speech
}
void Update()
{
if (Input.anyKeyDown)
Skip();
}
Or I have to declare global DialogObject.Node and assign it in LoadLine?
Comment
Answer by Slonika · Apr 02, 2016 at 05:58 PM
Found a workaround
IEnumerator Speech(DialogObject.Node node)
{
AudioSource speaker = ...; // get a audio source that is currenlty playing
while (speaker.isPlaying && !Input.GetButton("Jump")
yield return null;
speaker.Stop();
Next(node);
}
Follow this Question
Related Questions
IEnumerator instead of LateUpdate in unity 1 Answer
StopCoroutine not working. 0 Answers
After stop coroutine it resumes its task when I call start coroutine 1 Answer
Coroutine does not stop? 1 Answer
Coroutine not stopping 0 Answers