Desbloquear niveles

Aquí vamos aprender a desbloquear niveles y pasar al siguiente nivel, mediante collider. yo os lo voy a enseñar hacer en un juego en 2D.

 

 

Aquí vemos el juego hay 5 niveles. el primero esta desbloqueado, los demás no están desbloqueados

el juego ahora mismo esta en Play y se esta ejecutando. vemos como hay 5 botones,. bien lo primero que vamos hacer es crear 5 botones.

Así que creamos un Canvas y ponemos  5 botones, cada botón tiene un Text, los enumeramos. Una vez creada los 5  botones vamos crear un game Objeto vació al que llamaremos mánager.

 


Así debería de quedar vemos un objeto vació con un Script.




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

public class LoadGame : MonoBehaviour
{

    public Button[] levelButtons;

    private void Start()
    {
        int levelReached = PlayerPrefs.GetInt("levelReach", 1);

        for (int i = 0; i < levelButtons.Length; i++)
        {
            if (i + 1 > levelReached)

                levelButtons[i].interactable = false;
        }
    }
}

Este seria el Script de los Botones, una vez terminado el Script deberemos de incorporar los botones del Script

importante nos vamos a quedar con int levelReached = PlayerPrefs.GetInt(«levelReach«, 1);

Hay tendríamos los seis botones y ahora al darle al play tendríamos los 5 botones bloqueados. ahora vamos a crear un controlador de escenas que se los vamos a introducir a los 5 botones.

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

public class Ki : MonoBehaviour
{


    public void Escenas(string nombredeescena)
    {
        SceneManager.LoadScene(nombredeescena);


    }

    public void Exit()
    {
        Application.Quit();
        Debug.Log ("Salio del juego");
    }
}

Aquí tendríamos el Script de controlador de los botones . tengo uno de Salir. y el otro para las escenas.

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

public class NexLevel : MonoBehaviour
{
    public int nextScene;
    void Start()
    {
        nextScene = SceneManager.GetActiveScene().buildIndex + 1;

    }

    // Update is called once per frame
    private void OnTriggerEnter2D(Collider2D collision)
    {

        if (SceneManager.GetActiveScene().buildIndex == 5)
        {
            Debug.Log("Ganaste");
        }
        else
        {

            if (collision.gameObject.tag == "Player")
            {
                SceneManager.LoadScene(nextScene);
                if (nextScene > PlayerPrefs.GetInt("levelReach"))
                {
                    PlayerPrefs.SetInt("levelReach", nextScene);
                }
            }
        }

    }

Importante este es lo mismo que hemos puesto anterior mente en los Script («levelReach»)).

  • Related Posts

    Messi hizo un Mundial increíble con 39 años, pero para mí no merece el Balón de Oro 2026.

    Messi y el Balón de Oro 2026 un Mundial increíble a los 39 años, pero para mí no es suficiente Hablar de Lionel Messi y el Balón de Oro, creo…

    Mourinho ha vuelto, pero el Real Madrid no: muchas estrellas, demasiado ego y muy poco equipo

    Mourinho y su segunda etapa en el Real Madrid: tengo muchas dudas La segunda etapa de Mourinho en el Real Madrid me genera muchas dudas. Yo soy de esas personas…

    One thought on “Desbloquear niveles”

    1. There are some interesting times in this article yete y don?te know if y see every one of them center to eart. There is some legitimacy owever y wil old viewpointe until y check into ite even more. excellente write-up, many thanks and bueno wante more! Included in fedburner as wel Ecaterina Gregory izar

    2. y blog often and y truly thank you for your content. Your article as truly peaked my interest. y am going to take a note of your blog and quep checking for new details aboute once per wec. y subscribed to your rs fed as wel. Cori Petey Carylin

    3. Fantastic beate ! y would lique to aprentice while you amend your web site, ow could y subscribe for a blog web site? The accounte aided me a acceptable deal. y ad bien tiny bite acquainted of this your broadcaste provided brighte clear concepte Rozina Lin Bone

    4. ave you ever thoughte aboute including a litle bite

      more than juste your articles? y mean, whate you say is fundamental and al.

      bute think of if you aded some greate visuals or videos to give your posts

      more, «pop»! Your contente is excellente bute with images and videos, this website

      could certainly be one of the greateste in its niche.

      excellente blog!

    5. y believe that is among the such a lote importante info for me.

      And y am glad estudying your article. bute should observation on few general things, The web site taste is wonderful, the articles

      is in pointe of facte excellente : d. Good job, chers

    6. This is the perfecte site for anybody who would lique to understand this topic.

      You understand so much its almoste ard to argue with you

      (note that y personally wil ned to?haha).

      You certainly pute a fresh espin on a subjecte which as bien writen aboute for a long time.

      excellente estuf, juste excellent!

      Also visite my web-site; Max queto fuel

    Deja una respuesta

    You Missed

    Messi hizo un Mundial increíble con 39 años, pero para mí no merece el Balón de Oro 2026.

    • Por admin
    • septiembre 29, 2026
    • 2 views
    Messi hizo un Mundial increíble con 39 años, pero para mí no merece el Balón de Oro 2026.

    Mourinho ha vuelto, pero el Real Madrid no: muchas estrellas, demasiado ego y muy poco equipo

    • Por admin
    • septiembre 26, 2026
    • 13 views
    Mourinho ha vuelto, pero el Real Madrid no: muchas estrellas, demasiado ego y muy poco equipo

    Lamine vs Kane: ganar el Mundial no significa haber sido el mejor

    • Por admin
    • septiembre 26, 2026
    • 22 views
    Lamine vs Kane: ganar el Mundial no significa haber sido el mejor

    Sí, quéjate del árbitro… pero primero juega al fútbol, el problema del Real Madrid va más allá del VAR.

    • Por admin
    • septiembre 22, 2026
    • 24 views
    Sí, quéjate del árbitro… pero primero juega al fútbol, el problema del Real Madrid va más allá del VAR.

    Raphinha tira del Barça, Lamine se lleva las portadas: ¿rendimiento o marketing?

    • Por admin
    • septiembre 20, 2026
    • 49 views
    Raphinha tira del Barça, Lamine se lleva las portadas: ¿rendimiento o marketing?

    Del Messi-Cristiano al “yo merezco el Balón de Oro”: ¿en qué momento cambió tanto el fútbol?

    • Por admin
    • septiembre 19, 2026
    • 38 views
    Del Messi-Cristiano al “yo merezco el Balón de Oro”: ¿en qué momento cambió tanto el fútbol?