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;
}
}