Question by
SolarChaser13 · Jun 23, 2017 at 09:34 PM ·
uibuttoneventsystemgamepadpressing
How do I press an UI button with Gamepad controls?
I've been working on creating a basic menu in Unity 2D. I followed the live training video (provided by Unity) to learn the basics of the coding of it and how to navigate the buttons with a gamepad. However, the video did not explain how to use the gamepad buttons (A, B, etc.) to press the UI buttons. How would I do this is the code?
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.EventSystems;
public class SelectOnInput : MonoBehaviour {
public EventSystem eventSystem;
public GameObject selectedObject;
private bool buttonSelected;
private bool buttonClicked;
// Use this for initialization
void Start () {
}
// Update is called once per frame
void Update ()
{
if (Input.GetAxisRaw ("Vertical") != 0 && buttonSelected == false)
{
eventSystem.SetSelectedGameObject (selectedObject);
buttonSelected = true;
}
if (Input.GetButtonDown ("A") && buttonSelected == true)
{
//Code that presses down the button when selected.
}
}
private void OnDisable ()
{
buttonSelected = false;
}
}
Comment
Your answer
Follow this Question
Related Questions
UI Button not working? 0 Answers
Button not interactable but still responding to events. How do you fix this? 1 Answer
How do I NOT play a sound on the first selected button. 2 Answers
If I disable/enable my canvas (pause game menu), controller navigation in the canvas stops to work? 1 Answer
Why can't spam click on UI Image ? 0 Answers