I have a few scenes that load sequentially in single mode using a SceneManager script, and after the last scene the level is reset to re-load the first scene. The issue is after the first time around when each new scene loads it stutters, and the more times you loop around the worse the stutter gets. The only component set to DontDestroyOnLoad is the SceneManager, attached to an empty game object, so all scenes should be getting destroyed when a new scene is loaded. Any clues to why this stutter is happening would be appreciated. Here is the SceneManager script:
#pragma strict
import UnityEngine.SceneManagement;
private var counter =0;
private var level:int=0;
private var created = false;
function Start () {
if (!created) {
DontDestroyOnLoad(this.gameObject);
created = true;
}
}
function Update () {
if (Input.touchCount > 0 && Input.GetTouch(0).phase == TouchPhase.Began || Input.GetMouseButtonDown(0)) {
counter++;
if(counter==9){
// Debug.Log(level);
if(level<2) {
level++;
ChangeLevel(level);
} else {
level=0;
ChangeLevel(level);
}
counter=0;
}
}
}
function ChangeLevel(newLevel:int) {
var fadeTime = GetComponent(Fade).BeginFade(1);
yield WaitForSeconds(fadeTime);
// Debug.Log(newLevel);
SceneManager.LoadSceneAsync(newLevel,LoadSceneMode.Single);
}