Better way to create Events inside a StateMachineBehaviour
I would like to use events on StateMachineBehaviour instead of using bool parameters. But I was having a problem using delegate events and I don't have any Idea on how to access StateMachineBehavior from a MonoBehavior class. I don't want to spend much time So I made it worst like this.
public class DeficateState : StateMachineBehaviour {
public delegate void DeficateEvent();
public static event DeficateEvent OnPoop;
public static event DeficateEvent OnPee;
override public void OnStateUpdate(Animator animator, AnimatorStateInfo stateInfo, int layerIndex)
{
if (!update) return;
if (times > IdleTime)
{
update = false;
times = 0;
if(animator.GetInteger("IdleIndex") == 0){
if (OnPoop != null)
OnPoop();
}else{
if (OnPee != null)
OnPee();
}
}
times += Time.deltaTime;
}
I was able to unsubscribe manually but It gets more complicated when errors are rising up, and It takes me more time to review my code when I missed one. Can I use Unity Events? Sadly I've never tried using it.
Your answer
Follow this Question
Related Questions
Mecanim Drawer Animation problem? 0 Answers
Play sound when looking at an object for a certain amount of time 0 Answers
UnityEngine.GameObject' does not contain a definition for `SetSelectedGameObject' 0 Answers
Mecanim animation playing once on button press 2 Answers
Can't find Animator State/Invalid Layer Index in child object inside prefab 0 Answers