Hi guys,
I’m using a controller button to highlight 3 buttons (ammo selection).
The buttons get highlighted fine. The problem is that I need to execute a method when one of these buttons is highlighted. I don’t want the player to have to highlight the button THEN press OK. I found a whole bunch of threads on this but they all seem to involve a mouse. My game is played with a controller. The question is: How can I achieve this? I tried all the scripts found here and there but none of them work. Here is the last option I found. That code transforms the button into something else which I can’t access to make it intractable or not from another script. It also removes the OnClick that I would still like to keep for people not using a controller but using the keyboard instead. Any help would be appreciated. I spent all morning just trying to get this to work. I’m on 2018.3. Thanks.
using UnityEngine;
using UnityEngine.Events;
using UnityEngine.EventSystems;
using UnityEngine.UI;
//Use the Selectable class as a base class to access the IsHighlighted method
public class BuckShotSelected : Selectable
{
//Use this to check what Events are happening
BaseEventData m_BaseEvent;
void Update()
{
//Check if the GameObject is being highlighted
if (IsHighlighted(m_BaseEvent) == true)
{
//Output that the GameObject was highlighted, or do something else
Debug.Log("Selectable is Highlighted");
}
}
}