After you finished your animation keyframing, you can set a function(event) on to last frame of your animation. There is a add event button in animation window. Use it to fire a function via script.
I believe this is a bug with Unity 4.6 beta. I have spent the last couple of hours addressing it and the best I can do is delay the OnClick event by animation clip length.
It works but it’s not 100% accurate as Animator will sometimes spill over to Normal/Highlighted state due to clip length possibly being different.
all it do is that it will make all listenter off and when the event is triggered by animation (after the animation finished) it will make them on and invoke the functions…
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
using UnityEngine.Events;
public class ButtonController : MonoBehaviour {
private Button button;
public void Awake() {
button = GetComponent<Button>();
// disabling all the event listeners
SetListenersState(UnityEventCallState.Off);
}
private void OnButtonClick() {
AudioManager.self.Play("button");
// enabling the listeners again
SetListenersState(UnityEventCallState.EditorAndRuntime);
// calling all listeres
button.onClick.Invoke();
// disabling all the event listeners
SetListenersState(UnityEventCallState.Off);
}
private void SetListenersState(UnityEventCallState state) {
for(int i = 0; i < button.onClick.GetPersistentEventCount(); i++) {
button.onClick.SetPersistentListenerState(i, state);
}
}
}