Hello,
i have an animation attack that is called on Unity when i hit the attack button. It did not work as i've expected and the animation make unity freeze!
private void AttackState()//called by fixed update
{
if (attack>0)
{
canRunIdle = false;
animationControll("Attack one4", false, 1f);
skeletonAnimation.state.Event += OnEventAttack;//call the method OnEventCatch to follow event
}
}
//to track the SPINE event end_attack1
private void OnEventAttack(TrackEntry trackEntry, Spine.Event e)
{
if (e.Data.Name == "end_Attack")
{
canRunIdle = true;
Debug.Log("FROM playerMotor : end of attack 1 : " + canRunIdle);
}
}
the Debug.Log that shows the message "end of attack 1" is displayed many many times instead of one time per event. What i've expected is the debug.log would've displayed once per event, but the more i click and restart the animation, the more the debug.log is shown.
is the pic, i just clicked on the attack button once but i have 356 debug.log…
please help me because it causes lagg a lot if i click a lot.
Hello,
i solved my problem!
Its because the method was called by the update instead of the start!
So instead of listening one time, it is fired every frame!
So be sure to put the
SkeletonAnimation.State.Event += OnEvent
IN THE START NOT IN UPDATE
void Start()
{
SkeletonAnimation.State.Event += OnEvent
}