- Home /
Question by
Epsilone · Dec 25, 2020 at 02:55 PM ·
eventsselectable
Play sound when Selectable GameObject is selected
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 :/
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?
Comment
If your PlaySound component is attached to the same object with the Selectable component, I believe implementing the OnSelect method should do the trick:
https://docs.unity3d.com/2017.4/Documentation/ScriptReference/UI.Selectable.OnSelect.html