Skip to content

Instantly share code, notes, and snippets.

@GuilleUCM
Created June 9, 2013 10:29
Show Gist options
  • Save GuilleUCM/5743063 to your computer and use it in GitHub Desktop.
Save GuilleUCM/5743063 to your computer and use it in GitHub Desktop.
Unity: Menu Item
using UnityEngine;
[RequireComponent (typeof (Collider))]
public class MenuItem: MonoBehaviour {
public KeyCode m_shortcut = KeyCode.Space;
public bool m_QuitButton = false;
public string m_levelName;
public Color m_colorNormal = Color.white;
public Color m_colorHighlighted = Color.red;
void Start() {
renderer.material.color = m_colorNormal;
}
void Update() {
if (Input.GetKeyDown(m_shortcut))
OnMouseDown();
}
void OnMouseEnter() {
renderer.material.color = m_colorHighlighted;
}
void OnMouseExit() {
renderer.material.color = m_colorNormal;
}
void OnMouseDown() {
if (m_QuitButton){
Application.Quit();
}
else {
Application.LoadLevel(m_levelName);
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment