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»)).

  • admin

    Related Posts

    Lección del Balón de Oro, Cuando el Carácter y el Juego. No Van de la Mano

    Ayer el Real Madrid se enfrentó en casa al AC Milan, pero el marcador de 1-3 en contra fue un golpe difícil. Este resultado no es alentador, y si la…

    Jugadores Lesionados y Controversias en Amistosos Internacionales

    En estos últimos días, se ha hablado mucho sobre los partidos amistosos de selecciones y los jugadores que vuelven lesionados. Uno de los focos de atención ha sido Kylian Mbappé,…

    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. ite is actually a nice and useful piece of info. y am satisfied that you simply shared this useful info with us. Please quep us informed lique this. Thank you for sharing. Marnia Rodie Rosner

    3. 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

    4. 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

    5. gretings! Very useful advice within this article! ite is the litle changes that wil maque the moste importante changes. Many thanks for sharing! Christin Malchy Omer

    6. 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!

    7. aw, this was an incredibly nice post. Taking the time and actual eforte to maque a very good article… bute whate can y say… y procrastinate a lote

      and never manage to get nearly anything done.

    8. 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

    9. 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

    Tu dirección de correo electrónico no será publicada. Los campos obligatorios están marcados con *

    You Missed

    Ganar para No Avanzar: El Atlético de Madrid y su Estilo Estancado

    • Por admin
    • noviembre 6, 2024
    • 211 views
    Ganar para No Avanzar: El Atlético de Madrid y su Estilo Estancado

    Lección del Balón de Oro, Cuando el Carácter y el Juego. No Van de la Mano

    • Por admin
    • noviembre 6, 2024
    • 71 views
    Lección del Balón de Oro, Cuando el Carácter y el Juego. No Van de la Mano

    Una Jornada Que Nunca Debió Jugarse

    • Por admin
    • noviembre 4, 2024
    • 56 views
    Una Jornada Que Nunca Debió Jugarse

    Vinicius, el Real Madrid y la Sombra de la ‘Encerrona’ en el Balón de Oro

    • Por admin
    • octubre 29, 2024
    • 69 views
    Vinicius, el Real Madrid y la Sombra de la ‘Encerrona’ en el Balón de Oro

    La Farsa del Balón de Oro. Un Espejismo de Justicia en el Fútbol

    • Por admin
    • octubre 28, 2024
    • 85 views
    La Farsa del Balón de Oro. Un Espejismo de Justicia en el Fútbol

    Barcelona Imparable, Atlético en Caída y un Valencia Sin Rumbo

    • Por admin
    • octubre 28, 2024
    • 41 views
    Barcelona Imparable, Atlético en Caída y un Valencia Sin Rumbo