Better Code/Event System for Menu

I am working on a menu that is meant to have buttons that show quotation marks when you select them (like Silent Hill).


Scene View and Heirarchy

133993-u2.png
Event Trigger (used for both buttons)

I created event triggers inside the “BTN_” objects that change the alpha of the “Quote1” child object from 0 to 1 when the mouse is hovered over and back to 0 when the mouse isn’t over the button. Is there a way to make a better event system that also reacts to “wasd” and arrow keys? I’m preferably aiming to organize the menu and triggers in C#, but using components in the inspector is fine.

Packages Used

  • TextMesh Pro

EDIT: The parent system of my button is:

BTN_ (the button)
NewGameBtn (the text)
Quote1 (the quotation marks)

You could make a class that inherits from EventTrigger to deal with it. Like so…

using UnityEngine.EventSystems;
using UnityEngine.UI;

public class ButtonController : EventTrigger
{
    private string _buttonText;

    private Text _buttonTextBox;

    private void Start()
    {
        _buttonTextBox = GetComponentInChildren<Text>();
        _buttonText = _buttonTextBox.text;
    }

    public override void OnPointerEnter(PointerEventData eventData)
    {
        UpdateButtonText(true);
    }

    public override void OnPointerExit(PointerEventData eventData)
    {
        UpdateButtonText(false);
    }

    public override void OnSelect(BaseEventData eventData)
    {
        UpdateButtonText(true);
    }

    public override void OnDeselect(BaseEventData eventData)
    {
        UpdateButtonText(false);
    }

    private void UpdateButtonText(bool selected)
    {
        _buttonTextBox.text = selected ? "\"" + _buttonText + "\"" : _buttonText;
    }
}

If you remove the event trigger component and your quote child object, you can just put the above script on the button.