Loading next level issues (Bicker Style game)

Hi guys first off happy new year to you all i hope you have a great time :slight_smile:

So here is my problem, i have been struggling with this and i am sure it is a easy fix but i just can not work it out. I am building a bicker (arkanoid) style game and its coming along well but i am having issues moving to the next level. i currently have 2 levels and i have hard coded in “load level2” but now i wish to add additional levels (level3 ect)

The load level is attached to the Brick script once the last brick is destroyed level 2 successfully loads

as you can see i have tried various ways but none successful (these are commented out)

Thank you very much in advance, it is greatly appreciated

current working loads level2

if ( numBricks <= 0 ) {

			Application.LoadLevel("level2");
		}

Code attempted

if ( numBricks <= 0 ) {
			// Load a new level??
			Application.LoadLevel("level2");
			//Application.LoadLevel("Level"+level); 
			//Application.LoadLevel (Application.loadedLevel+1);
		}

Full script Source code it may help

using UnityEngine;
using System.Collections;

public class BrickScript : MonoBehaviour {
	
	static int numBricks = 0;
	public int pointValue = 1;
	public int hitPoints = 1;
	public int powerUpChance = 3;
	//public int level = 0;
	
	public GameObject[] powerUpPrefabs;
	
	// Use this for initialization
	void Start () {
		numBricks++;
	}
	
	// Update is called once per frame
	void Update () {
		
	}
	
	void OnCollisionEnter( Collision col ) {
		hitPoints--;
		
		if ( hitPoints <= 0 ) {
			Die();
		}
	}
	
	void Die() {
		Destroy( gameObject );
		PaddleScript paddleScript = GameObject.Find ("paddle").GetComponent<PaddleScript>();
		paddleScript.AddPoint(pointValue);
		numBricks--;
		
		if ( Random.Range(0, powerUpChance) == 0 ) {
			Instantiate( powerUpPrefabs[ Random.Range(0, powerUpPrefabs.Length) ] , transform.position, Quaternion.identity );
		}
		
		if ( numBricks <= 0 ) {
			// Load a new level??
			Application.LoadLevel("level2");
			//Application.LoadLevel("Level"+level); 
			//Application.LoadLevel (Application.loadedLevel+1);
		}
	}
}

As far as I can see, the Destroy(gameObject) is being called before anything else, interrupting the parsing of the script.
As a sidenote numblocks, score and level changing should be on a centralized object.
Hope this helps you.

thanks for the advice, it is greatly appreciated i will look in to those errors now but i am not 100% sure how to fix them :frowning:

But i did manage to sort out the load leavel problem in the end with the below code

#			if( Application.loadedLevel + 1 < Application.levelCount )
				Application.LoadLevel( Application.loadedLevel + 1 );

on an additional note how would i add a timer that will say wait a few seconds before loading the next level

here is the completed script with the level transitions working

using UnityEngine;
using System.Collections;

public class BrickScript : MonoBehaviour {
	
	static int numBricks = 0;
	public int pointValue = 1;
	public int hitPoints = 1;
	public int powerUpChance = 3;
	//public int level = 0;
	
	public GameObject[] powerUpPrefabs;
	
	// Use this for initialization
	void Start () {
		numBricks++;
	}
	
	// Update is called once per frame
	void Update () {
		
	}
	
	void OnCollisionEnter( Collision col ) {
		hitPoints--;
		
		if ( hitPoints <= 0 ) {
			Die();
		}
	}
	
	void Die() {
		Destroy( gameObject );
		PaddleScript paddleScript = GameObject.Find ("paddle").GetComponent<PaddleScript>();
		paddleScript.AddPoint(pointValue);
		numBricks--;
		
		if ( Random.Range(0, powerUpChance) == 0 ) {
			Instantiate( powerUpPrefabs[ Random.Range(0, powerUpPrefabs.Length) ] , transform.position, Quaternion.identity );
		}
		
		if ( numBricks <= 0 ) {
			// Load a new level??

			if( Application.loadedLevel + 1 < Application.levelCount )
				Application.LoadLevel( Application.loadedLevel + 1 );

		}
	}
}

i believe its something like but i am unable to make it work in my current code

			yield return new WaitForSeconds(1.8); Application.LoadLevel("level2");