Skip to content

Instantly share code, notes, and snippets.

@hcosta
Created May 29, 2017 14:50
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save hcosta/34b4b485c56df3248e9eae73002b129f to your computer and use it in GitHub Desktop.
Save hcosta/34b4b485c56df3248e9eae73002b129f to your computer and use it in GitHub Desktop.
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.SceneManagement;
public class Menu : MonoBehaviour {
public GameObject flecha, lista;
int indice = 0;
void Start () {
Dibujar();
}
void Update () {
bool up = Input.GetKeyDown("up");
bool down = Input.GetKeyDown("down");
if (up) indice--;
if (down) indice++;
if (indice > lista.transform.childCount-1) indice = 0;
else if (indice < 0) indice = lista.transform.childCount-1;
if (up || down) Dibujar();
if (Input.GetKeyDown("return")) Accion();
}
void Dibujar(){
Transform opcion = lista.transform.GetChild(indice);
flecha.transform.position = opcion.position; // Pivote a la izquierda
}
void Accion(){
Transform opcion = lista.transform.GetChild(indice);
if (opcion.gameObject.name == "Salir"){ // Conseguir nombre del objeto
print("Cerrando juego... En playmode y HTML no funciona");
Application.Quit();
} else {
SceneManager.LoadScene(opcion.gameObject.name);
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment