- Home /
Menu Selection using 360 Controller
I would like the menu buttons to be able to be scrolled through and selected by using the 360 controller instead of the mouse cursor. i am using a 3D menu for the main menu and a delegate menu in a pause menu. If possible I would like to do this for both. I am using C# so please answer it with C# script instead of Javascript.
this is a what i have in the Delegate Menu so far.
using UnityEngine;
using System.Collections;
public class DelegateMenu : MonoBehaviour { private delegate void MenuDelegate(); private MenuDelegate menuFunction;
private float screenHeight;
private float screenWidth;
private float buttonHeight;
private float buttonWidth;
// Use this for initialization
void Start()
{
screenHeight = Screen.height;
screenWidth = Screen.width;
buttonHeight = screenHeight * 0.3f;
buttonWidth = screenWidth * 0.4f;
menuFunction = anyKey;
}
void OnGUI()
{
menuFunction();
}
void anyKey()
{
if (Input.anyKey)
{
menuFunction = mainMenu;
}
GUI.skin.label.alignment = TextAnchor.MiddleCenter;
GUI.Label(new Rect(screenWidth * 0.45f, screenHeight * 0.1f, screenWidth * 0.1f, screenHeight * 0.1f), "Press any key to continue");
}
void mainMenu()
{
if (GUI.Button(new Rect((screenWidth - buttonWidth) * 0.5f, screenHeight * 0.1f, buttonWidth, buttonHeight), "Start Game"))
{
Application.LoadLevel("Level1");
}
if (GUI.Button(new Rect((screenWidth - buttonWidth) * 0.5f, screenHeight * 0.5f, buttonWidth, buttonHeight), "Quit Game"))
{
Application.Quit();
}
}
and this is what i have for the 3D menu:
using UnityEngine;
using System.Collections;
public class MenuObject : MonoBehaviour { public bool isQuit = false; void OnMouseEnter() { renderer.material.color = Color.red;
}
void OnMouseExit()
{
renderer.material.color = Color.white;
}
void OnMouseDown()
{
if (isQuit)
{
Application.Quit();
}
else
{
Application.LoadLevel(2);
}
}
}
}enter code here
Your answer
Follow this Question
Related Questions
Multiple Cars not working 1 Answer
Distribute terrain in zones 3 Answers
Problem with Pause Menu because of WaitForSeconds 1 Answer