Skip to content

Instantly share code, notes, and snippets.

@ArieLeo
Forked from unity3dcollege/AnimatorPanel.cs
Created March 15, 2022 10:28
Show Gist options
  • Save ArieLeo/7fb9a3d30abb1cc4b53ce39ac54bf45d to your computer and use it in GitHub Desktop.
Save ArieLeo/7fb9a3d30abb1cc4b53ce39ac54bf45d to your computer and use it in GitHub Desktop.
using TMPro;
using UnityEngine;
using UnityEngine.UI;
public class AnimatorPanel : MonoBehaviour
{
[SerializeField] Animator _animator;
[SerializeField] Button _button;
void Start()
{
foreach (var parameter in _animator.parameters)
{
if (parameter.type == AnimatorControllerParameterType.Trigger)
AddButton(parameter);
}
}
void AddButton(AnimatorControllerParameter parameter)
{
var button = Instantiate(_button, transform);
foreach(var tmpText in button.GetComponentsInChildren<TMP_Text>())
tmpText.text = parameter.name;
button.onClick.AddListener(() => _animator.SetTrigger(parameter.nameHash));
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment