Hoy vamos aprender a seleccionar el personaje, el video lo tenéis en mi cuenta de YouTube. Aquí
ahora lo que vamos hacer será seleccionar a nuestros personajes
Aquí tenemos nuestros personajes, serán cuatro y atreves de un botón elegiremos cual será el seleccionado, . los cuatros tienen el mismo movimiento es un script simplemente que va hacia todos lados de la pantalla, y si ahora mismo le diese al play movería los 4 personajes, pero yo lo que quiero es un personaje
Así que lo siguiente que vamos hacer será crear un objeto vacío al que llamaremos Player, y en ese Objeto vacío pone a nuestros personajes que en mi caso serán estos 4
Hay tenemos a nuestros cuatro personajes, yo ahora los cambiare el nombre para no liarme, una vez hecho esto vamos al objeto vacío que hemos creado Player, y le creamos un Script, que yo le voy a llamar seleccióondejugadores, y programamos lo siguiente
using System.Collections; using System.Collections.Generic; using UnityEngine; public class Seleccciondejugador : MonoBehaviour { private List<GameObject> Jugadores; private int SelecctionIndex = 0; public GameObject[] avatarS; void Start() { Jugadores = new List<GameObject>(); foreach (Transform t in transform) { Jugadores.Add(t.gameObject); t.gameObject.SetActive(false); } Jugadores[SelecctionIndex].SetActive(true); } public void ActivadorAvatar(GameObject targerAvatar) { foreach (GameObject avatar in avatarS) { avatar.SetActive(false); } targerAvatar.SetActive(true); } public void select(int index) { if (index == SelecctionIndex) return; if (index < 0 || index >= Jugadores.Count) return; Jugadores[SelecctionIndex].SetActive(false); SelecctionIndex = index; Jugadores[SelecctionIndex].SetActive(true); } }
Una vez hecho esto Guardamos nuestro Script, y vamos a Unity, hay realizaremos lo siguiente
Ahora en Size ponemos 4, he incorporamos nuestros personajes que son los mismos que tenemos de hijos, en el objeto vacío de Player
Aquí están nuestros player a los que yo cambie el nombre. ahora nos queda la parte mas fácil, vamos añadir cuatro botones
Hay tenemos nuestros cuatro botones, le Text lo borre ahora vamos al botón NARA
Ahora solo nos quedaría introducir nuestro Personaje
En NOne (GAme Object), pondriamos nuestro Player, que en mi caso seria El naranja, puesto que es el botón NARA y hacemos lo mismo con los demás botones.
thanks.
Do you mind if I quote a few of your articles as long as I provide credit and
sources back to your site? My blog is in the very same
area of interest as yours and my visitors would
certainly benefit from a lot of the information you provide here.
Please let me know if this alright with you. Thanks a
lot!
You should take part in a contest for one of the best sites online.
I’m going to recommend this site!