Take the 2-minute tour ×
Game Development Stack Exchange is a question and answer site for professional and independent game developers. It's 100% free, no registration required.

So in my game I've got a timer script, which counts down unless the game is paused, but whenever the variable for pausing is true, something in the timer script makes the editor itself crash, and I have to pull out the task manager to close unity because it freezes up completly.

Timer.cs

using UnityEngine; using System.Collections;

public class Timer : MonoBehaviour { public LevelManager levelManager;

// Use this for initialization
void Start () {
    levelManager = FindObjectOfType<LevelManager>();
    StartCoroutine ("timerUpdate");
}

// Update is called once per frame
void Update () {
}
IEnumerator timerUpdate (){
    while (levelManager.levelTimeSeconds>0) {
        if (levelManager.isPause== false){
            yield return new WaitForSeconds(1);
            levelManager.levelTimeSeconds -= 1;
        }
    }
    levelManager.isOver = true;

}

}

Anyone have any idea what's causing the editor to crash once isPause is true??

share|improve this question

1 Answer 1

up vote 0 down vote accepted

when it becomes true your loop will run forever :) Better use:

while (levelManager.levelTimeSeconds>0 && levelManager.isPause== false)
{
        yield return new WaitForSeconds(1);
        levelManager.levelTimeSeconds -= 1;
}
share|improve this answer
    
I can't believe I didn't notice that before, thanks for the help. –  LevelForge Jul 2 at 21:18

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.