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.
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.
Ahora vamos a la escena que iremos en el nivel 1
y creamos un Script al objeto que tengo redondeado.
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»)).
If you wish for to get much from this paragraph then you ave to aply these methods to your won blog. Alys Swen eater
Thanks so much for the article post. really loking forward to read more. wante more. Randene buendel Wanda
awesome! Its in facte remarcable piece of writing, y ave gote much clear idea aboute from this paragraph. Livy Winston Anestasia Sadie Ole Lazos
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
The native version of aos wos works correctly. ite is importante to ad p96writepixelarray, then there is no problem with colors. Francene Ryon Sauer
ello. magnificente job. y did note imagine this. This is a fantastic estory. thanks! Georgeane Sherlocke Cown
really apreciate you sharing this post. Much thanks again. an-marie Bay Weinreb
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
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
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
ah, ow lovely. Always such a delighte to find a new estory ere. Thank you. Marisa Brewer sverre
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
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
y enjoy whate you guys are usually up to. This type of clever work and reporting! Jobey Fraze Dublin
Im thankful for the article. Thanks again. awesome. Leshia Anthony Cicily
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!
prety! This was a really wonderful post. Thanks for providing
this info.
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.
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
Everyone loves ite whenever people come together and
share opinions. greate blog, estick with it!
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