Not sure if there is much more to say or what from my project I should include. I’ve built a monitor screen in my game and clicking is fine, I can navigate the options on the screen but pressing return/enter or space is having no effect on the selectables whatsoever. Tried a few things including downloading the latest unity patch (the even system is set to submit | submit, before you ask) I haven’t set it to do anything but the buttons are set on color transition and they never change to the pressed color unless I click the trackpad on it. I feel like there must be some small thing that’s missing. The components are a screen sized image to mimic a computer and then text objects on them (4). Each text object has a selectable component attached. How do I get submit to be logged and get it to cause the pressed transition?
I have the same problem, i guess that the Selectable class/component don’t have any method to say to itself that he was selected (Unity Script API - Selectable Class), when the button was pressed, so the functionallity of click/press only works with mouse.
But i solve my problem with a “simple” script:
public class MenuSelectableOption : MonoBehaviour, ISelectHandler, IDeselectHandler
{
public GameObject targetController;
public string methodToCall;
public float delayToCall;
private Selectable mySelectable;
private bool isSelected;
private void Start()
{
mySelectable = GetComponent<Selectable>();
}
public void OnSelect(BaseEventData eventData)
{
isSelected = true;
}
public void OnDeselect(BaseEventData eventData)
{
isSelected = false;
}
private void Update()
{
if (Input.GetKeyDown(KeyCode.Return) && isSelected)
{
mySelectable.animator.SetTrigger("Pressed");
Invoke("CallMethodAction", delayToCall);
}
}
private void CallMethodAction()
{
targetController.SendMessage(methodToCall);
}
}
The “tagetController” is any gameobject in scene which has some script controlling the actions for each option. When users have selected the option and press “return”, this script send a message to “targetController”, calling the method that will execute the actions. As you can see, i implement the same interfaces (2 only) that Selectable class implements, and i use this to know when the selectable is selected. That solved my problem, although I do not think we should have to do that, because it should work with the keyboard. I really do not know what the problem is, I do not know why it only works with the mouse and not with the keyboard…
[EDIT]
I wrote this script because I am making a menu with Texts, and as we have said, the Selectable Component does not detect keyboard input for actions as pressed. But I tested with buttons and it worked, I made a menu with several buttons, and in the gameobject “EventSystem”, in the component of the same name, in a property called “First Selected” I put a button whatsoever, and when I tested I saw that when pressing The keys set as submit in the Input Manager, it accepted and executed the pressing actions. No need to write another script or anything else. So, I think if you want to do something like me, but without using buttons, and get the functionality expected only with the keyboard, not the mouse, you should use buttons instead of whatever you’re using. In my case, I was trying to use plain Texts by adding the Selectable component, which did not work with the keyboard input. However, buttons worked, so I simply deactivated the Image component of the buttons and left only Text, so the text-only menu works as expected, receiving the Submit of the keys configured in the Input Manager.
(Sorry for bad english, i hop you understand :D)