Play sound when Selectable is selected

Ok the solution MUST be simple but I just can’t find it, it’s so frustrating ><
I have a simple object with a “Selectable” Component and a custom “PlaySound” Component.

My goal is just to play a sound when this object is selected, exept I can’t find any event on with I could plug my custom method :confused:
My playsound Component is basicaly

public class PlaySound: MonoBehaviour
{   
    private void OnEnable()
    {    
        //GetComponent<Selectable>().OnSelect += HandleOnSelectEvent;        
        //Not working because OnSelect in not an event 
    }

    void HandleOnSelectEvent(){
        print("WIP: Now I play my UISelected Sound");
    }

What am I missing?

I believe you need to add this interface to your script and implement OnSelect:

https://docs.unity3d.com/Packages/com.unity.ugui@1.0/api/UnityEngine.EventSystems.ISelectHandler.html

1 Like