I’m trying to make a combo chain in my script. It goes like this.
I’m sorry if this is a little confusing so I made some indications of my code, down below it.
public void Combos(){
// COMBO CHAIN 1
if (Input.GetKey (KeyCode.X) && Restart == true && Continue == false && Combo == 0) {
CTime = 2f;
Combo = 1;
ReTime = 3f;
Continue = false;
anim.SetTrigger ("AttackSoft");
Attacking = true;//My Attacking Boolean
StartCoroutine (ACoroutine ());
Cloned = (GameObject)Instantiate (HitBox, transform.position, transform.rotation);
StartCoroutine (CTimer ());
StartCoroutine (Destroy());
StartCoroutine (ComboRestart());
}
// COMBO CHAIN 2
if (Input.GetKey (KeyCode.X) && Continue == true && Combo == 1 && Restart == false) {
Continue = false;
ReTime = 4f;
Combo = 2;
print ("Combo Chain 2");
CTime = 3f;
StopCoroutine (CTimer ());
StopCoroutine (ComboRestart());
Coroutine
StartCoroutine (CTimer ());
StartCoroutine (ComboRestart());
}
// COMBO CHAIN 3
if (Input.GetKey (KeyCode.X) && Continue == true && Combo == 2 && Restart == false) {
print ("Combo Chain 3 You ended the Combo");
Combo = 3;
StartCoroutine (ComboRestart());
}
CTime
This is my duration time Coroutine which tells me if my character can Continue attacking again or not.
Here’s the Code for it.
IEnumerator CTimer(){
Continue = false;
print ("Hold On!");
yield return new WaitForSeconds (CTime);
print ("You may attack again");
Continue = true;
}
ReTime
This is my Duration Time for the Coroutine which tells me if my Characters Combo Chain Restarted or not.
Here’s the Code
IEnumerator ComboRestart(){
Restart = false;
yield return new WaitForSeconds (ReTime);
print ("Combo restarted");
Restart = true;
}
Combo
This is just a number that signifies which Combo number I’m currently at.
The reason why my Timer’s numbers were increasing is because I thought by increasing the number of my timer it will increase the duration, but it didn’t.
What my problem here is. Everytime I press the X Key Again for the second time.
Continue Switches to False, and Restart is Checked as True.
Like everytime!
I’d appreciate anyone who could help me with this.