Help, with SimulateWin :

cant write proper code compatible with unity 2017 for "SimulateWin"
Her is my script,

using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.SceneManagement;

public class Brick : MonoBehaviour {
    
    public Sprite[] hitSprites;
    public static int breakableCount = 0;

    private int maxHits;
    private int timesHit;
    private bool isBeakable;



    // Use this for initialization
    void Start () {
        isBeakable = (this.tag == "Breakable");

        if (isBeakable)
        {
            breakableCount++;
            print(breakableCount); 
        }
        timesHit = 0;
  
    }
	
	// Update is called once per frame
	void Update () {

       
    }

    void OnCollisionEnter2D(Collision2D col)
    {
        
        if (isBeakable)
        {
            HandleHits();
        }
       
    }

    void HandleHits ()
    {
        maxHits = hitSprites.Length + 1;
        timesHit++;

        if (timesHit >= maxHits)
        {
            breakableCount--;
            print(breakableCount);
            Destroy(this.gameObject);
        }
        else
        {
            LoadSprites();
        }
    }




    void LoadSprites ()
    {
        int spriteIndex = timesHit - 1;
        if (hitSprites[spriteIndex])
        {
            this.GetComponent<SpriteRenderer>().sprite = hitSprites[spriteIndex];
        }
    }
       
}

I don’t want directly to load next level, I want it to show you won or win screen.
please help.

So what have you tried to do so far and what are the error messages you’re getting? Right now your script doesn’t have any win conditions that I can see.

1 Like

I tried everything as in the lecture but it is showing error, that is why I undo all.
I need help to write new code which will lead me to win screen I don’t know what to do that is why I posted my code if someone would tell me how to do it.

Whenever breakable count <=0 it should load win screen, then I will add something new to load next level.
but for now, I want it to load win screen.
I don want LoadNextLevel code

I can’t recall the lecture number off of the top of my head, but you add a line of code within the HandleHits method in due course which calls a method from LevelManager, I believe it’s;

levelManager.BrickDestroyed;

Obviously, this method has to be created within LevelManager, it checks to see how many bricks are remaining and then loads the next level.

Your build settings hold the order of the levels (scenes), so, when there are no more playable scenes, the next one in the order would be the Win scene.

If the issue is that you are getting errors messages due to Application.Load now being obsolete within Unity 2017, take a look at lecture number 6, it provides a list of code changes which are required due to the API changes between the version of Unity used in the course and that of version 5+.

Privacy & Terms