- Home /
Null
Startcoroutine not working second time
Startcoroutine Not working second time, method btn() is attached to a button and when it's clicked it's not starting the coroutine.
please help ... Thanks in advance.
using System.Collections; using System.Collections.Generic; using UnityEngine; using UnityEngine.UI; public class abc : MonoBehaviour {
private IEnumerator cou;
public static bool sol;
bool task =false;
public Text txt;
void Start ()
{
cou = gameoveractivate ();
}
void Update ()
{
if (sol == false)
{
sol = true;
StartCoroutine (cou);
}
if (task == true)
{
StopCoroutine (cou);
task = false;
}
}
public void btn()
{
sol = false;
}
IEnumerator gameoveractivate() { yield return new WaitForSeconds(5); Debug.Log ("Couroutine Scuccess"); txt.gameObject.SetActive (true); yield return new WaitForSeconds(2); txt.gameObject.SetActive (false); task = true; }
}
Answer by Cuttlas-U · Sep 27, 2017 at 01:27 PM
hi; try do stop the corutines once u want to run it again maybe last corutine is not finished yet ;
public void btn()
{
StopAllCoroutines();
sol = false;
}
Answer by goutham12 · Sep 27, 2017 at 01:38 PM
StartCoroutine (cou); in the above what is that cou is it a method or what?
attach the below code to your method. and check
public void BtnClick(){
print("button Click");
StartCoroutine (Calling());
}
Ienurator Calling(){
print("called");
yield return null;
}