Hi all, i have a problem with my code, the code ensures that when the level is finished it will load a new scene, but i want that it 2 sec. wait with loading the scene, so i did that with: Yield return new WaitForSeconds(2);, and used the IEnumerator, but my whole code didn’t work anymore, does somebody know what the problem is? i’m btw not a pro in this things. I use C# for 4 months now. I hope somebody can help me, thanks!
public bool[] holeTrigger = new bool[6];
protected string currentLevel;
protected int worldIndex;
protected int levelIndex;
// Use this for initialization
void Start () {
//save the current level name
currentLevel = Application.loadedLevelName;
}
// Update is called once per frame
void Update () {
//move the player based on left and right arrow keys
transform.Translate(Input.GetAxis("Horizontal")*Time.deltaTime*10f, 0, 0); //get input
}
public IEnumerator TriggerHole(int index) {
holeTrigger[index] = true; //Set the hole trigger to true
//Check if all holes have been triggered
if (AllTriggered) {
UnlockLevels (); //unlock next level funxtion
Yield return new WaitForSeconds(2);
Application.LoadLevel ("fLevel1");
}
}
//This method will iterate through each of the triggers in the array and return false if any of them are not true.
public bool AllTriggered {
get{
bool b = true;
foreach(bool bX in holeTrigger){
if(!bX)
b = false;
}
return b;
;}
}
protected void UnlockLevels (){
//set the playerprefs value of next level to 1 to unlock
for(int i = 0; i < LockLevel.worlds; i++){
for(int j = 1; j < LockLevel.levels; j++){
if(currentLevel == "Level"+(i+1).ToString() +"." +j.ToString()){
worldIndex = (i+1);
levelIndex = (j+1);
PlayerPrefs.SetInt("level"+worldIndex.ToString() +":" +levelIndex.ToString(),1);
}
}
}
}