Coroutine feels like its only pausing and then continuing from the time it was stopped at! I have it that when he appears, you have 4 secs to play the decoy or else you are dead meat! and the first time works just fine but then when it happens again, its totally broken! pls help.
public class AI : MonoBehaviour
{
public GameObject speed;
private int movementprob;
public AudioSource warning;
public AudioSource decoy;
public AudioSource sadspeed;
IEnumerator Secondswait()
{
Debug.Log("Seconds wait");
yield return new WaitForSeconds(5);
Debug.Log("wait over");
StartCoroutine(Speedmovement());
}
// Start is called before the first frame update
void Start()
{
Debug.Log("Start");
survivalCoroutine = SurvivalTime();
StartCoroutine(Secondswait());
}
private IEnumerator survivalCoroutine;
IEnumerator Speedmovement()
{
Debug.Log("Randomizing");
movementprob = Random.Range(0, 10);
if(movementprob == 6)
{
Debug.Log("success");
speed.SetActive(true);
warning.Play();
StartCoroutine(survivalCoroutine);
}
else
{
Debug.Log("Fail");
yield return new WaitForSeconds(1);
Debug.Log("Repeating");
StartCoroutine(Speedmovement());
}
}
void Update()
{
}
IEnumerator SurvivalTime()
{
Debug.Log("Survive!");
yield return new WaitForSeconds(4);
SceneManager.LoadScene(1);
}
public void StopSpeed()
{
StopCoroutine(survivalCoroutine);
StartCoroutine(SpeedSounds());
}
IEnumerator SpeedSounds()
{
decoy.Play();
yield return new WaitForSeconds(1);
speed.SetActive(false);
sadspeed.Play();
yield return new WaitForSeconds(1);
StartCoroutine(Speedmovement());
}
}