popcorn/popcorn/Assets/MyGame/Scripts/AnimationButton.cs

23 lines
550 B
C#
Raw Normal View History

using System;
using UniRx;
using UniRx.Triggers;
using UnityEngine;
using UnityEngine.UI;
namespace MyGame.Scripts
{
[RequireComponent(typeof(Animator))]
public class AnimationButton : MonoBehaviour
{
private static readonly int Active = Animator.StringToHash("Active");
private void Start()
{
var animator = GetComponent<Animator>();
gameObject.OnEnableAsObservable().Subscribe(_ =>
{
animator.SetTrigger(Active);
}).AddTo(this);
}
}
}