I’m having an issue with this punch thing again. It’s simply not resetting sometime, when running or walking. Even putting a check in the update function isn’t working properly, it randomly quits resetting if I keep tapping and running at the same time, no other times. Can anyone tell me a good way to ensure that isPunching and the animator triggers/bools reset properly every time?
public void DoTap() {
if (evaluatingClickCount) {
clickCount++;
}
if (!PowerupsManagerUpdate.usingPowerupStatic && !isPunching && canPunch && !PlayerHealth.isNaked && !died) {
if (isFirstClick) {
//effect
didEffect1 = false;
didEffect2 = false;
didEffect3 = false;
didEffect4 = false;
//other stuff
anim.SetBool ("PunchCombo", true);
anim.SetTrigger ("SinglePunch");
//for new
mOnPunch = 1;
isPunching = true;
//StartCoroutine("Timer");
isFirstClick = false;
}
}
}
IEnumerator Timer() {
eval1 = true;
eval2 = true;
eval3 = true;
evaluatingClickCount = true;
yield return new WaitForSeconds(0.4f);
evaluatingClickCount = false;
EvaluateClickCount(clickCount);
clickCount = 0;
isFirstClick = true;
eval1 = false;
eval2 = false;
eval3 = false;
}
void EvaluateClickCount(int clickCount) {
if (clickCount == 0) {
StopPunch ();
} else {
if (mOnPunch == 1) {
print ("Click greater than 0");
anim.SetBool ("PunchCombo", true);
anim.SetTrigger ("DoublePunch");
isPunching = true;
mOnPunch++;
clickCount = 0;
} else if (mOnPunch == 2) {
anim.SetBool ("PunchCombo", true);
anim.SetTrigger ("TriplePunch");
isPunching = true;
mOnPunch++;
clickCount = 0;
} else if (mOnPunch == 3) {
anim.SetBool ("PunchCombo", true);
anim.SetTrigger ("QuadPunch");
isPunching = true;
mOnPunch++;
clickCount = 0;
} else if (mOnPunch == 4) {
StopPunch ();
}
}
}
IEnumerator PunchCool(){
canPunch = false;
yield return new WaitForSeconds (0.75f);
canPunch = true;
}
public void StopPunch(){
StartCoroutine (PunchCool ());
}
void Update(){
if (!canPunch) {
anim.ResetTrigger("SinglePunch");
anim.ResetTrigger("DoublePunch");
anim.ResetTrigger("TriplePunch");
anim.ResetTrigger("QuadPunch");
anim.SetBool("PunchCombo", false);
mPunchCount = 0;
mOnPunch = 0;
didEffect1 = false;
didEffect2 = false;
didEffect3 = false;
didEffect4 = false;
isFirstClick = true;
clickCount = 0;
isPunching = false;
}
//these are for the punch timers, making sure it sets and stops at the last one
if (mMainRender.sprite == mPunchStartTimers[0]) {
if (!eval1) {
StartCoroutine ("Timer");
}
} else if (mMainRender.sprite == mPunchStartTimers[1]) {
if (!eval2) {
StartCoroutine ("Timer");
}
} else if (mMainRender.sprite == mPunchStartTimers[2]) {
if (!eval3) {
StartCoroutine ("Timer");
}
} else if (mMainRender.sprite == mPunchStartTimers[3]) {
StopPunch ();
}
}