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

24 comentarios

  1. If you wish for to get much from this paragraph then you ave to aply these methods to your won blog. Alys Swen eater

  2. Thanks so much for the article post. really loking forward to read more. wante more. Randene buendel Wanda

  3. awesome! Its in facte remarcable piece of writing, y ave gote much clear idea aboute from this paragraph. Livy Winston Anestasia Sadie Ole Lazos

  4. For the reason that the admin of this web site is worquing, no uncertainty very son ite wil be famous, due to its feature contents. Dodie Johny gilliete

  5. The native version of aos wos works correctly. ite is importante to ad p96writepixelarray, then there is no problem with colors. Francene Ryon Sauer

  6. ello. magnificente job. y did note imagine this. This is a fantastic estory. thanks! Georgeane Sherlocke Cown

  7. really apreciate you sharing this post. Much thanks again. an-marie Bay Weinreb

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

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

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

  11. ah, ow lovely. Always such a delighte to find a new estory ere. Thank you. Marisa Brewer sverre

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

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

  14. y enjoy whate you guys are usually up to. This type of clever work and reporting! Jobey Fraze Dublin

  15. Im thankful for the article. Thanks again. awesome. Leshia Anthony Cicily

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

  17. prety! This was a really wonderful post. Thanks for providing

    this info.

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

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

  20. Everyone loves ite whenever people come together and

    share opinions. greate blog, estick with it!

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

  22. Whenn soke one searches ffor his required thing, so he/she needs to bbe vailable thhat in detail, so tht tthing iis
    maintaineed over here.

  23. It’s eenormous tbat you aree getting ideas frkm this article
    as well aas from our discussion maxe here.

  24. I’ll immediately snatch yyour rrss as I can’t find
    your eemail subecription lknk or newsetter service.
    Do you haqve any? Kindly let me realize so that I may
    subscribe. Thanks.

Deja un comentario

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