Fixing Animation calls in a combo Script
The problem is that
the combo animation plays when its combo number "ComboInt" and it's own animation number "PlayerCurrentCombo" matches the ones I've set to it
each animation has these 2 variables
and a combo would contain many animations
and should be running when you press the right key in the right time
"timeLastKeyPressed" "allowedTimeBetweenKeys"
the problem is that only the first animation plays and it gets stuck, doesn't even get back to idle animation
it should be a combo script for one like DmC
This is the script:
using UnityEngine;
using System.Collections;
public class ComboSie : MonoBehaviour {
// Here type the sequence of KeyCodes for your special combo.
private KeyCombo combo1 = new KeyCombo(new KeyCode[] { KeyCode.Q, KeyCode.E, KeyCode.E });
private KeyCombo combo2 = new KeyCombo(new KeyCode[] { KeyCode.E, KeyCode.E });
public Animator ComboCont;
public static Animator PlayerAnimator;
void Awake()
{
//PlayerAnimator = (Animator) GameObject.FindGameObjectWithTag("Player").GetComponent(typeof(Animator));
PlayerAnimator = ComboCont;
Debug.Log (ComboCont);
Debug.Log (PlayerAnimator);
}
void FixedUpdate()
{
//PlayerAnimator.applyRootMotion = true;
if (combo1.Check())
{
PlayerAnimator.SetInteger("ComboInt",1);
/*
if(PlayerAnimator.GetCurrentAnimatorStateInfo(0).IsTag("Combo1") && !PlayerAnimator.GetCurrentAnimatorStateInfo(0).IsTag("Combo2") )
{
PlayerAnimator.SetBool("ComboPlaying",true);
PlayerAnimator.SetInteger("ComboInt",1);
}
// Play the 'combo1' special combo.
*/
}
if (combo2.Check())
{
PlayerAnimator.SetInteger("ComboInt",2);
/*
if(PlayerAnimator.GetCurrentAnimatorStateInfo(0).IsTag("Combo2") && !PlayerAnimator.GetCurrentAnimatorStateInfo(0).IsTag("Combo1") )
{
PlayerAnimator.SetBool("ComboPlaying",true);
PlayerAnimator.SetInteger("ComboInt",2);
}
*/
}
/*if(!PlayerAnimator.GetCurrentAnimatorStateInfo(0).IsTag("Combo1") && PlayerAnimator.GetBool("ComboPlaying") == true)
{
PlayerAnimator.SetBool("ComboPlaying",false);
PlayerAnimator.SetInteger("ComboInt",0);
}
if(!PlayerAnimator.GetCurrentAnimatorStateInfo(0).IsTag("Combo2") && PlayerAnimator.GetBool("ComboPlaying") == true)
{
PlayerAnimator.SetBool("ComboPlaying",false);
PlayerAnimator.SetInteger("ComboInt",0);
}
*/
}
public class KeyCombo
{
//public Animator PlayerAnimator = (Animator) GameObject.FindGameObjectWithTag("Player").GetComponent(typeof(Animator));
public Animator PlayerAnimator;
public KeyCode[] Keys;
private int currentIndex = 0; //moves along the array as Keys are pressed.
public float allowedTimeBetweenKeys = 1f; //tweak as needed.
private float timeLastKeyPressed;
public KeyCombo(KeyCode[] b)
{
Keys = b;
}
public bool Check()
{
Debug.Log (ComboSie.PlayerAnimator);
PlayerAnimator = ComboSie.PlayerAnimator;
if (Time.time > timeLastKeyPressed + allowedTimeBetweenKeys)
currentIndex = 0;
if (currentIndex < Keys.Length)
{
if (Input.GetKeyDown(Keys[currentIndex]))
{
Debug.Log(PlayerAnimator);
timeLastKeyPressed = Time.time;
currentIndex++;
Debug.Log ( "Playing Animation" );
Debug.Log ( currentIndex );
Debug.Log ( PlayerAnimator.GetCurrentAnimatorStateInfo (0).IsName("Combo1") );
//Here play the animation according to your combo sequence AND your currentIndex.
PlayerAnimator.SetInteger("PlayerCurrentCombo",currentIndex);
return true;
}
if (currentIndex >= Keys.Length)
{
PlayerAnimator.SetInteger("PlayerCurrentCombo",0);
currentIndex = 0;
//Here play the last animation and the special combo animation OR just play the special combo animation.
//return true;
}
else return false;
}
return false;
}
}
}
Comment