I put together this combo script and have been troubleshooting for a while and can’t seem to stop the problem.
The problem is when it receives input from the z key it runs though all the attack sequence and shows only the last animation.
I don’t get why it’s doing this as I set it up to stop receiving input with a bool after z is pushed.
Also I put in some co routines to pause long enough to play the animation, but it looks like they are ignored.
Any advice would be appreciated.
using UnityEngine;
using System.Collections;
public class AttackControl : MonoBehaviour {
private PlayerControl playerControlLink;
private Animator animatorLink;
public enum ComboState
{
AttackState = 0,
AttackStateL1 = 1,
AttackStateL2 = 2,
AttackStateL3 = 3,
AttackStateL4 = 4,
AttackStateR1 = 5,
AttackStateR2 = 6,
AttackStateR3 = 7,
AttackStateR4 = 8
}
public ComboState comboLevel = ComboState.AttackState;
private Collider2D atkFocusRight1;
private Collider2D atkFocusLeft1;
public bool enableColliderRight1 = false;
public bool enableColliderLeft1 = false;
public bool resetComboTimer = false;
public bool stopAttack = false;
public float nextComboTimeLimit = 0.0f;
public int comboState = 0;
void Awake()
{
atkFocusRight1 = GameObject.FindGameObjectWithTag("AttackRightFocus1").collider2D;
atkFocusLeft1 = GameObject.FindGameObjectWithTag ("AttackLeftFocus1").collider2D;
animatorLink = GameObject.FindGameObjectWithTag ("Player").GetComponent<Animator>();
}
void Start ()
{
playerControlLink = FindObjectOfType<PlayerControl>();
}
void Update ()
{
atkFocusRight1.collider2D.enabled = false;
atkFocusLeft1.collider2D.enabled = false;
if (Input.GetKeyDown ("z") && stopAttack == false)
{
stopAttack = true;
ComboStateActivate ();
}
if (resetComboTimer == true)
{
nextComboTimeLimit -= Time.deltaTime;
if (nextComboTimeLimit <= 0)
{
comboState = 0;
resetComboTimer = false;
nextComboTimeLimit = 0.5f;
comboLevel = ComboState.AttackState;
}
}
}
void FixedUpdate()
{
if (enableColliderRight1 == true)
{
atkFocusRight1.collider2D.enabled = true;
enableColliderRight1 = false;
}
if (enableColliderLeft1 == true)
{
atkFocusLeft1.collider2D.enabled = true;
enableColliderLeft1 = false;
}
}
void SetAttackState()
{
switch (comboLevel)
{
case ComboState.AttackState:
break;
case ComboState.AttackStateL1:
enableColliderLeft1 = true;
animatorLink.SetTrigger ("attackL1");
StartCoroutine (AttackWait1());
resetComboTimer = true;
nextComboTimeLimit = 0.5f;
comboState = 1;
print ("Combo 1 left");
comboLevel = ComboState.AttackState;
stopAttack = false;
break;
case ComboState.AttackStateL2:
enableColliderRight1 = true;
animatorLink.SetTrigger ("attackL2");
StartCoroutine (AttackWait2());
resetComboTimer = true;
nextComboTimeLimit = 0.5f;
comboState = 2;
print ("Combo 2 Move left");
comboLevel = ComboState.AttackState;
stopAttack = false;
break;
case ComboState.AttackStateL3:
enableColliderRight1 = true;
animatorLink.SetTrigger ("attackL3");
StartCoroutine (AttackWait3());
resetComboTimer = true;
nextComboTimeLimit = 0.5f;
comboState = 3;
print ("Combo 3 Move left");
comboLevel = ComboState.AttackState;
stopAttack = false;
break;
case ComboState.AttackStateL4:
enableColliderRight1 = true;
animatorLink.SetTrigger ("attackL4");
StartCoroutine (AttackWait4());
resetComboTimer = true;
// nextComboTimeLimit = 0.5f;
comboState = 0;
print ("Combo 4 Move left");
comboLevel = ComboState.AttackState;
stopAttack = false;
break;
case ComboState.AttackStateR1:
enableColliderRight1 = true;
animatorLink.SetTrigger ("attackR1");
StartCoroutine (AttackWait1());
resetComboTimer = true;
nextComboTimeLimit = 0.5f;
comboState = 1;
print ("Combo 1 right");
comboLevel = ComboState.AttackState;
stopAttack = false;
break;
case ComboState.AttackStateR2:
enableColliderRight1 = true;
animatorLink.SetTrigger ("attackR2");
StartCoroutine (AttackWait2());
resetComboTimer = true;
nextComboTimeLimit = 0.5f;
comboState = 2;
print ("Combo 2 Move right");
comboLevel = ComboState.AttackState;
stopAttack = false;
break;
case ComboState.AttackStateR3:
enableColliderRight1 = true;
animatorLink.SetTrigger ("attackR3");
StartCoroutine (AttackWait3());
resetComboTimer = true;
nextComboTimeLimit = 0.5f;
comboState = 3;
print ("Combo 3 Move right");
comboLevel = ComboState.AttackState;
stopAttack = false;
break;
case ComboState.AttackStateR4:
enableColliderRight1 = true;
animatorLink.SetTrigger ("attackR4");
StartCoroutine (AttackWait4());
resetComboTimer = true;
// nextComboTimeLimit = 0.5f;
comboState = 0;
print ("Combo 4 Move right");
comboLevel = ComboState.AttackState;
stopAttack = false;
break;
}
}
void ComboStateActivate()
{
if (comboState == 0 && playerControlLink.checkRL == true)
{
comboLevel = ComboState.AttackStateR1;
SetAttackState ();
}
if (comboState == 0 && playerControlLink.checkRL == false)
{
comboLevel = ComboState.AttackStateL1;
SetAttackState ();
}
if (comboState == 1 && playerControlLink.checkRL == true)
{
comboLevel = ComboState.AttackStateR2;
SetAttackState ();
}
if (comboState == 1 && playerControlLink.checkRL == false)
{
comboLevel = ComboState.AttackStateL2;
SetAttackState ();
}
else if (comboState == 2 && playerControlLink.checkRL == true)
{
comboLevel = ComboState.AttackStateR3;
SetAttackState ();
}
if (comboState == 2 && playerControlLink.checkRL == false)
{
comboLevel = ComboState.AttackStateL3;
SetAttackState ();
}
if (comboState == 3 && playerControlLink.checkRL == true)
{
comboLevel = ComboState.AttackStateR4;
SetAttackState ();
}
if (comboState == 3 && playerControlLink.checkRL == false)
{
comboLevel = ComboState.AttackStateL4;
SetAttackState ();
}
}
public IEnumerator AttackWait1()
{
yield return new WaitForSeconds (0.07f);
}
public IEnumerator AttackWait2()
{
yield return new WaitForSeconds (0.08f);
}
public IEnumerator AttackWait3()
{
yield return new WaitForSeconds (0.08f);
}
public IEnumerator AttackWait4()
{
yield return new WaitForSeconds (0.23f);
}
}