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

    ¿Por qué hablamos tanto de Lamine si Raphinha está siendo el mejor del Barcelona?

    Raphinha, el gran olvidado del Barcelona: cuando el marketing pesa más que el rendimiento Raphinha me parece uno de los grandes olvidados de este Barcelona, y sinceramente creo que es…

    Lamine tiene el futuro, pero el presente del Barcelona se llama Raphinha

    El Barça gana 5-2, Lamine vuelve a marcar, pero para mí el alma de este equipo sigue siendo Raphinha Ayer el Barcelona ganó 5-2 al Rayo Vallecano y, evidentemente, estamos…

    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

    ¿Por qué hablamos tanto de Lamine si Raphinha está siendo el mejor del Barcelona?

    • Por admin
    • septiembre 3, 2026
    • 21 views
    ¿Por qué hablamos tanto de Lamine si Raphinha está siendo el mejor del Barcelona?

    Lamine tiene el futuro, pero el presente del Barcelona se llama Raphinha

    • Por admin
    • septiembre 1, 2026
    • 23 views
    Lamine tiene el futuro, pero el presente del Barcelona se llama Raphinha

    El tiempo también gana a Messi: Argentina dice adiós a una leyenda irrepetible

    • Por admin
    • septiembre 1, 2026
    • 23 views
    El tiempo también gana a Messi: Argentina dice adiós a una leyenda irrepetible

    Raphinha y diez más: el Barça gana, pero Lamine Yamal vuelve a dejar dudas

    • Por admin
    • agosto 28, 2026
    • 27 views
    Raphinha y diez más: el Barça gana, pero Lamine Yamal vuelve a dejar dudas

    Cuando Mbappé y Vinícius juegan el uno para el otro, el Real Madrid es otro equipo

    • Por admin
    • agosto 27, 2026
    • 45 views
    Cuando Mbappé y Vinícius juegan el uno para el otro, el Real Madrid es otro equipo

    Lamine Yamal no es Messi ni Cristiano: dejémosle escribir su propia historia

    • Por admin
    • agosto 27, 2026
    • 32 views
    Lamine Yamal no es Messi ni Cristiano: dejémosle escribir su propia historia