- Home /
Custom Behaivior on highlighting button
Hello.
I'm trying to design a main menu for a game, where buttons are 'highlighted' with an arrow pointing it.
Basically, something like this:
...and the arrow moves when the button is to be highlighted, like when the mouse cursor enters the button area, or the button was selected via keyboard, etc. I'm trying to deal with keyboard input using the Navigation feature in the button object's Button (Script) component.
My current Implementation has the pointer as a separate GameObject, and the buttons have the following script attatched:
using UnityEngine;
using UnityEngine.EventSystems;
using UnityEngine.UI;
public class PointerController : MonoBehaviour, IPointerEnterHandler {
private GameObject pointer;
void Start () {
pointer = GameObject.Find("/Canvas/Pointer");
}
public void OnPointerEnter(PointerEventData eventData) {
MovePointer();
}
void MovePointer() {
if (!pointer.GetComponent<Text>().enabled) {
pointer.GetComponent<Text>().enabled = true;
}
Vector3 temp = pointer.transform.position;
temp.y = transform.position.y;
pointer.transform.position = temp;
}
}
This works for mouse, but doesn't work with keyboard. How can I make this work with keyboard, or more generically, anything that would highlight the button? Thanks in advance.
asdfasdf.png
(5.9 kB)
Comment