- Home /
Resetting Combos
Yo, guys. I'm trying to implement a combo system. So far, I've made it so that after a certain amount of attacks, there's a delay before you can attack again. What I need to do now is make it so that the combo resets after a certain period of inaction before completion of said combo.
Here's what I have so far:
Combo Function
function Update () {
if(swingCounter == 1 && Input.GetButtonDown ("Fire1") && busy == false && !controller.IsMoving())
{
isCombo = true;
swingCounter = 2;
SendMessage ("DidPunch");
busy = true;
}
if(swingCounter == 2 && Input.GetButtonDown ("Fire1") && busy == false && !controller.IsMoving())
{
swingCounter = 3;
SendMessage ("DidPunch2");
busy = true;
}
if(swingCounter == 3 && Input.GetButtonDown ("Fire1") && busy == false && !controller.IsMoving())
{
swingCounter = 4;
SendMessage ("DidPunch3");
busy = true;
}
if(swingCounter == 4 && Input.GetButtonDown ("Fire1") && busy == false && !controller.IsMoving())
{
swingCounter = 1;
SendMessage ("DidPunch4");
busy = true;
}
}
Attack function (All four are the same, currently)
function DidPunch () { print ("Check two"); animation.Play("attack"); audio.PlayOneShot(swordSwing); yield WaitForSeconds(punchHitTime); var pos = transform.TransformPoint(punchPosition); var enemies : GameObject[] = GameObject.FindGameObjectsWithTag("Enemy"); var environ : GameObject[] = GameObject.FindGameObjectsWithTag("Environment");
for (var go : GameObject in enemies)
{
var enemy = go.GetComponent(EnemyDamage);
if (enemy == null)
continue;
if (Vector3.Distance(enemy.transform.position, pos) < punchRadius)
{
print ("Enemy hit!");
enemy.SendMessage("ApplyDamage", punchHitPoints);
// Play sound.
if (punchSound)
audio.PlayOneShot(punchSound);
}
}
yield WaitForSeconds(punchTime - punchHitTime);
busy = false;
}
And my failed attempt at a timer reset thingy
function Update (){
if (isCombo){
swingTimer += Time.deltaTime;
if (swingTimer > 2){
print("Resetting combo!");
swingCounter = 1;
isCombo = false;
}
}
}
Any help is appreciated!
Answer by Maarten · Dec 11, 2010 at 09:01 AM
First of all, you can change your Update function to have a little less code:
if(Input.GetButtonDown ("Fire1") && busy == false && !controller.IsMoving())
{
if (swingCounter < 4)
{
swingCounter +=1;
}
else
{
swingCounter = 1;
}
SendMessage ("DidPunch" + swingCounter);
busy = true;
}
Furtherwise for the timer, what doesnt work? When i need to do something timewise i do the following:
var comboStartTime : float;
if (isCombo) { if (comboStartTime = 0) { comboStartTime = Time.time; } else { if (Time.time - comboStartTime >= 2) { print("Resetting combo!");
swingCounter = 1;
isCombo = false; comboStartTime = 0 } }
Thanks a bunch, $$anonymous$$aarten. It works perfectly! The only thing I need now is to give it a delay after a combo reset. What's the easiest way for that?
Well you could add another time, lets say comboResetTime. Set it when the combo is resetted, and then use Time.time - comboResetTime == How much your delay is. When the delay is enough, set isCombo to true
Your answer
![](https://koobas.hobune.stream/wayback/20220613090603im_/https://answers.unity.com/themes/thub/images/avi.jpg)
Follow this Question
Related Questions
Cooldown Function Problem 1 Answer
Resetting a timer after game over 1 Answer
Touchscreen Combo System Issue 0 Answers
Reset a Timer made with .fillAmount 1 Answer