Hi,
Working on the button system.
We have mouse clicking on buttons working(using the default system).
We need proper keyboard input for buttons([Up], [Down], [Enter]).
Issue we face is that there is a default keyboard input for buttons.
How can we disable default keyboard input for Unity GUI button?
Let us know, thanks!
Jesse
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class ButtonsKeyboard : MonoBehaviour
{
GameObject ButtonSelectorLeftSprite;
GameObject ButtonSelectorRightSprite;
Vector3 position;
// Start is called before the first frame update
void Start()
{
}
public void SetupButtonSelectors(float posY)
{
ButtonSelectorLeftSprite = GameObject.Find("ButtonSelectorLeft");
position = ButtonSelectorLeftSprite.transform.position;
position.y = (posY / 100.0f);
ButtonSelectorLeftSprite.transform.position = position;
ButtonSelectorRightSprite = GameObject.Find("ButtonSelectorRight");
position = ButtonSelectorRightSprite.transform.position;
position.y = (posY / 100.0f);
ButtonSelectorRightSprite.transform.position = position;
}
// Update is called once per frame
void Update()
{
if (GlobalVariables.DelayAllUserInput > 0) GlobalVariables.DelayAllUserInput--;
if (GlobalVariables.DelayAllUserInput == 0)
{
if (GlobalVariables.ScreenToDisplay == 2)
{
if (Input.GetKey("up"))
{
if (GlobalVariables.CurrentlySelectedButton > 0)
{
GlobalVariables.CurrentlySelectedButton--;
}
else
{
GlobalVariables.CurrentlySelectedButton = 5;
}
float yPos = ( 110 - (50*GlobalVariables.CurrentlySelectedButton) );
SetupButtonSelectors(yPos);
GlobalVariables.SoundEffectToPlay = 3;
GlobalVariables.DelayAllUserInput = 5;
}
else if (Input.GetKey("down"))
{
if (GlobalVariables.CurrentlySelectedButton < 5)
{
GlobalVariables.CurrentlySelectedButton++;
}
else
{
GlobalVariables.CurrentlySelectedButton = 0;
}
float yPos = (110 - (50 * GlobalVariables.CurrentlySelectedButton));
SetupButtonSelectors(yPos);
GlobalVariables.SoundEffectToPlay = 3;
GlobalVariables.DelayAllUserInput = 5;
}
}
}
}
}
