LevelManager.cs is working if I start my first play through. However, if I lose and click start from the main menu and beat Level_1, Level_2 does not load.
public void LoadLevel(string name){
Debug.Log("Level load requested for: " + name);
Application.LoadLevel (name);
}
public void QuitRequest(){
Debug.Log ("I want to quit!");
Application.Quit ();
}
public void LoadNextLevel(){
Application.LoadLevel (Application.loadedLevel + 1);
}
public void BrickDestroyed(){
if(Brick.breakableCount <= 0){
LoadNextLevel();
}
}
Here’s my Brick.cs in case the issue has anything to do with SimulateWin();
public static int breakableCount = 0;
public AudioClip crack;
public Sprite[]hitSprites;
private int timesHit;
private LevelManager levelManager;
private bool isBreakable;
// Use this for initialization
void Start () {
isBreakable = (this.tag == "Breakable");
//Keep track of breakable bricks
if (isBreakable){
breakableCount++;
}
timesHit = 0;
levelManager = GameObject.FindObjectOfType<LevelManager>();
}
// Update is called once per frame
void Update () {
}
void OnCollisionEnter2D (Collision2D col) {
AudioSource.PlayClipAtPoint(crack,transform.position);
if (isBreakable){
HandleHits();
}
}
void HandleHits(){
timesHit++;
int maxHits = hitSprites.Length + 1;
if (timesHit >= maxHits){
breakableCount--;
levelManager.BrickDestroyed();
Destroy (gameObject);}
else {LoadSprites();
}
}
void LoadSprites(){
int spriteIndex = timesHit - 1;
if (hitSprites[spriteIndex]) {
this.GetComponent<SpriteRenderer>().sprite = hitSprites[spriteIndex];
}
}
//TODO Remove this method once we can win
void SimulateWin(){
levelManager.LoadNextLevel();
}