Hi guys first off happy new year to you all i hope you have a great time
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);
}
}
}