- Home /
UI Button onClick Events have no "animation.play()"
Hi there,
I have gameobject A with a button-component and gameobject B with an animation-component (legacy since it's cheaper). When I use the buttons "On Click" in the inspector - not in the script, in other words: drag'n'drop the gameobject B into and look at the dropbown-menu, choose the "animation"-component, I can't seem to find the "play"-function. I could use the "blend"-function but I think this costs more than just play without blend.
Did I miss something or do I have to make it with an extra script?
No idea, but you can always add a Listener via script calling any function you like.
Answer by rknapp · Sep 07, 2018 at 04:35 PM
I believe it is because the Play method on the Animation has a return type of bool, and is therefor not an Action<>. I've tested this by creating other components, and only the void-returning methods show up in the OnClick handler. Here's a little helper component I made to get around it.
[RequireComponent(typeof(Animation))]
public class AnimationTrigger : MonoBehaviour
{
private Animation _animation;
private void Awake()
{
_animation = GetComponent<Animation>();
}
public void Play()
{
_animation?.Play();
}
}