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
0
Question by Gucci Gagan · Nov 19, 2013 at 07:27 AM · invokerepeatingkillcombo

Kill Streak Help

Hi, I was having some issues with my kill streak script.

I think InvokeRepeating would be the best option.

 void Update () 
     {
         InvokeRepeating("StreakTimer", 1.0F, 1.0F);
     }

 void StreakTimer()
     {    
         if(killTimer > 0)
         {
             //TODO increment when enemy dies
             tempComboNum++;
         }
         
         if (--killTimer == 0) 
          {
             tempComboNum = 0;
             CancelInvoke ("StreakTimer");
         }
 
     }

I then update the gui text with the tempComboNum.

The issue

How do i increment the combo when an enemy dies? The kill streak script is attached to main camera and theres an enemyAI script attached to each enemy.

I used this as reference:

http://answers.unity3d.com/questions/64832/player-kill-streak.html

Please help! thank you!

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

3 Replies

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

Answer by woodoo · Jan 14, 2014 at 03:55 AM

They way i would do this is something like that:

  1. Check if an enemy was killed

  2. If so, increment the killStreak and stop the Coroutine called ResetStreak

  3. Start the coroutine ResetStreak (It will set killStreak to 0 after 'X' seconds.

  4. Loop it (just write the code inside Update()

Here's a snippet to help you to write it:

 int killStreak = 0;
 int resetTime = 4;
 
 void Update()
 {
     if (!enemyKilled)
         return;
 
     killStreak += 1;
     StopCoroutine("ResetStreak");
     StartCoroutine(ResetStreak());
 }
 
 void ResetStreak()
 {
     yield return new WaitForSeconds(resetTime);
     killStreak = 0;
 }

Note that "enemyKilled" variable will be some expression you'll write to check if you've killed an enemy.

Hope it helps.

Comment
Add comment · Show 1 · 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 Gucci Gagan · Mar 10, 2014 at 09:57 AM 0
Share

your method wont work because the script that stops and starts the coroutines when an enemy dies, needs to be on the enemey. And when the enemy dies, the script becomes inactive.

Is there another method of doing this?

avatar image
0

Answer by CipherZero · Jan 14, 2014 at 03:40 AM

you may want to avoid using InvokeRepeating() in Update(), it tends to get messed up. Instead of this, you can try to put InvokeRepeating() in somewhere that will be called once only, like Start()

Comment
Add comment · Show 1 · 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 Gucci Gagan · Mar 10, 2014 at 09:58 AM 0
Share

thank you for pointing that out!

avatar image
0

Answer by Gucci Gagan · Mar 10, 2014 at 01:16 PM

I got it finally. I just had to create the coroutine in another script and start and stop it from the enemy script when the enemy dies.

I wasn't aware you could call coroutines from other scripts.

THANK YOU!!

Comment
Add comment · 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

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

19 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

Change InvokeRepeating in another script 1 Answer

problem with shooting killing script 1 Answer

How to make a Kill Counter 1 Answer

Problem with combo attacks 2 Answers

Display var on gui not working... 2 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