Created
March 9, 2022 18:08
-
-
Save unity3dcollege/aef44f434dde4eae5ce3b0ce977ec796 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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