- Home /
Problem when trying to select buttons with the keyboard
Sorry about my english, I am Brazilian.
I am using this script from the live training "Creating a Main Menu" to select some UI buttons using the keyboard, it works fine, however when I click on a button and set the intractable to false the script stops working and does not select the other active buttons.
Anyone know how to keep script running while there are interactive buttons on the scene?
using UnityEngine;
using System.Collections;
using UnityEngine.EventSystems;
public class SelectOnInput : MonoBehaviour
{
public EventSystem eventSystem;
public GameObject selectedObject;
private bool buttonSelected;
void Update()
{
if (Input.GetAxisRaw("Horizontal") != 0 && buttonSelected == false)
{
eventSystem.SetSelectedGameObject(selectedObject);
buttonSelected = true;
}
}
private void OnDisable()
{
buttonSelected = false;
}
}
Comment
Your answer
