Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 13 Next capture
2021 2022 2023
1 capture
13 Jun 22 - 13 Jun 22
sparklines
Close Help
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
avatar image
2
Question by McMutton · Dec 11, 2010 at 04:57 AM · timerresetattackcombo

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!

Comment
Add comment
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users

1 Reply

· Add your reply
  • Sort: 
avatar image
2
Best Answer

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 } }

Comment
Add comment · Show 2 · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image McMutton · Dec 11, 2010 at 04:41 PM 0
Share

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?

avatar image Maarten · Dec 11, 2010 at 09:29 PM 0
Share

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

Hint: You can notify a user about this post by typing @username

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this Question

Answers Answers and Comments

No one has followed this question yet.

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

Why is the timer increasing after every reset? 3 Answers


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges