- Home /
Here to share! Animation Transition Handler (buttoncountflagger.cs)
Hello! So I tend to browse here when I'm looking for that one perfect word to fill a formula and such, we all come from somewhere, so I wrote a nice script here that handles inputs to trigger next animations based on if the state of the animator is in a state that it can handle receives. It also force fixes transitions based on the end of a sequence. This code is great if you want to work in a GCD counter on a loop animation, either a neutral state or an "in transition state" if you want to work in some sort of combo animation outcome, but anyway this forces a change in state to handlers assigned to inputs. The inputs themselves can be inflated using a list format, most of the items here could be parse lists to more higher level functionality, but this utility is a strong basis for animator-controlled forking timelines.
Enjoy!
using System.Collections; using System.Collections.Generic; using UnityEngine;
public class buttoncountflagger : MonoBehaviour { public int delta; public int tier1; public int tier2; public int tier3; public Animator anim; public bool cliploop; AnimatorClipInfo[] m_CurrentClipInfo; public bool internalflag;
// Start is called before the first frame update
void Start()
{
anim = gameObject.GetComponent<Animator>();
delta = 0;
StartCoroutine(Transitioner());
}
// Update is called once per frame
void Update()
{
m_CurrentClipInfo = anim.GetCurrentAnimatorClipInfo(0);
cliploop = m_CurrentClipInfo[0].clip.isLooping;
if ( cliploop == true)
{
delta = 0;
}
if (delta == 0)
{
if (Input.GetButtonDown("Fire1"))
{
tier1 = 100;
}
if (Input.GetButtonDown("Fire2"))
{
tier2 = 10;
}
if (Input.GetButtonDown("middlemousebutton"))
{
tier3 = 1;
}
}
else if (cliploop == false)
{
internalflag = false;
}
}
void LateUpdate()
{
if (cliploop == true)
{
delta = tier1 + tier2 + tier3;
if (internalflag == true)
{
delta = 0;
}
if (delta == 1 || delta == 10 || delta == 100)
{
if (delta == 100)
{
anim.SetTrigger("Tier 1");
internalflag = true;
}
if (delta == 10)
{
anim.SetTrigger("Tier 2");
internalflag = true;
}
if (delta == 1)
{
anim.SetTrigger("Tier 3");
internalflag = true;
}
}
}
}
IEnumerator Transitioner()
{
while (true)
{
if (internalflag == true)
{
delta = 0;
}
}
}
}