- Home /
Animator problem
hi lot of times when i play "Spell 2" after "spell 1" ends fast the trigger calls but the animation doesn't play the character goes to default "T pose" for some time "the time the animation that didnt play takes", here is the code anyone can help pls
using System.Collections; using System.Collections.Generic; using UnityEngine;
public class SpellSystem : MonoBehaviour { #region Singelton public static SpellSystem instance; private void Awake() { instance = this; } #endregion
[Header("Spell 1")]
public float Spell_1_Damage;
public float Spell_1_Range;
public float Spell_1_CD;
float Spell_1_FixedCD;
public GameObject Spell_1_VFX;
public Transform Spell_1_InstantiatePosition;
[Header("Spell 2")]
public float Spell_2_Damage;
public float Spell_2_Range;
public float Spell_2_CD;
float Spell_2_FixedCD;
public GameObject Spell_2_VFX;
public Transform Spell_2_InstantiatePosition;
#region Variables
PlayerMove playermove;
GeneralPlayer generalplayer;
bool CanAttack;
float Distance;
[HideInInspector] public GameObject Enemy;
Animator anim;
#endregion
void Start()
{
generalplayer = GeneralPlayer.instance;
anim = GetComponentInChildren<Animator>();
playermove = GetComponent<PlayerMove>();
}
void Update()
{
CanAttack = generalplayer.CanAttack;
Distance = generalplayer.Distance;
Enemy = generalplayer.Enemy;
Cds();
Spells_Trigger();
}
void Spells_Trigger() ////////// General Spell Trigger
{
if (CanAttack == true)
{
if (Input.GetKeyDown(KeyCode.Alpha1) && Spell_1_FixedCD <= 0 && Distance <= Spell_1_Range && GO == true)
{
FaceTargetDontMove();
anim.SetTrigger("Spell_1");
Spell_1_FixedCD = Spell_1_CD;
}
else if (Input.GetKeyDown(KeyCode.Alpha2) && Spell_2_FixedCD <= 0 && Distance <= Spell_2_Range && GO == true)
{
FaceTargetDontMove();
anim.SetTrigger("Spell_2");
Spell_2_FixedCD = Spell_2_CD;
}
}
else
{
anim.ResetTrigger("Spell_1");
anim.ResetTrigger("Spell_2");
}
}
void FaceTargetDontMove()
{
generalplayer.CanMove = false;
generalplayer.CanAttack = false;
playermove.FaceTarget(Enemy.transform);
}
void Cds()
{
//Spell 1 CD
Spell_1_FixedCD -= Time.deltaTime;
//Spell 2 CD
Spell_2_FixedCD -= Time.deltaTime;
//Spell 3 CD
//Spell 4 CD
//Spell 5 CD
}
}
Your answer
![](https://koobas.hobune.stream/wayback/20220612204522im_/https://answers.unity.com/themes/thub/images/avi.jpg)
Follow this Question
Related Questions
Animation not looping 1 Answer
Mixamo animations do not play in inspector 0 Answers
Apply root motion to bones which are not children of the root motion node 1 Answer
Does Animate Physics mode execute animations only in FixedUpdate? 0 Answers
How to apply Animator to different game objects (when animations affect children) 1 Answer