I just need to run a sound file when a button has been highlighted but not selected. How would I go about this?
If you use Sprite. Do what @KdRWaylander said.
But if you use new unity ui.
Use Unity event system
By click at that button. And add component Event Trigger.
Then add OnPointerEnter (When mouse highlight it)
But if you want as a script. Just add script to that button and set that button interacable to false (in case if script not work) Then just add interface to that class like this.
public class ButtonHighlight : Monobehaviour , IPointerEnterHandler
.....
public void OnPointer()
{
Debug.Log("Pointer over!);
}
IPointerHandler is need this namespace
using UnityEngine.EventSystem;
Hope that what you looking for…
Turns out this was what I was looking for:
using UnityEngine;
using UnityEngine.Events;
using UnityEngine.EventSystems;
public class ReadMeButton : MonoBehaviour, ISelectHandler , IPointerEnterHandler
{
// When highlighted with mouse.
public void OnPointerEnter(PointerEventData eventData)
{
// Do something.
Debug.Log("<color=red>Event:</color> Completed mouse highlight.");
}
// When selected.
public void OnSelect(BaseEventData eventData)
{
// Do something.
Debug.Log("<color=red>Event:</color> Completed selection.");
}
}
Hi,
Try this kind of message:
- OnMouseEnter
- OnMouseOver
- OnMouseExit
They’re called in any script on the the gameobject (tho it must have a collider).
void OnMouseEnter () {
// [...]
}