Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 12 Next capture
2021 2022 2023
1 capture
12 Jun 22 - 12 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 /
  • Help Room /
avatar image
0
Question by lbryan212 · Feb 05, 2019 at 07:23 PM · time.deltatimetimer-script

change timer float while still counting down

I'm working on a simple Multi-Kill script for my game.


 using System.Collections;
 using System.Collections.Generic;
 using UnityEngine;
 
 public class KillManager : MonoBehaviour
 {
     [Header("Player Statistics")]
     public float kills;
     public float prevKills;
     public float deaths;
     [Header("Multi-Kill Timer")]
     public float speed;
     public float killTimer;
     public float killtimerReset;
     public bool killChain;
     public float chainKills;
     [Header("Multi-Kill Status")]
     public bool doubleKill;
     public bool tripleKill;
     public bool quadKill;
     public bool pentaKill;
     
 
 
     // Start is called before the first frame update
     void Start()
     {
         prevKills = 0;
     }
 
     
 
 
     void multiTimer()
     {
         if(kills > prevKills)
         {
             killChain = true;
             if (killChain)
             {
                 killTimer -= speed * Time.deltaTime;
             }
             
 
             if(killTimer <= 0)
             {
                 killChain = false;
                 
                 prevKills = kills;
             }
 
 
 
 
 
 
             if(chainKills == 2)
             {
                 doubleKill = true;
                 
                 
 
 
             }
 
             if (chainKills == 3)
             {
                 tripleKill = true;
 
             }
 
             if (chainKills == 4)
             {
                 quadKill = true;
 
             }
 
             if (chainKills == 5)
             {
                 pentaKill = true;
 
             }
 
         }
 
 
 
     }
     // Update is called once per frame
     void Update()
     {
         multiTimer();
 
         chainKills = kills - prevKills;
 
 
         if (doubleKill)
         {
             tripleKill = false;
             quadKill = false;
             pentaKill = false;
 
         }
         if (tripleKill)
         {
             doubleKill = false;
             quadKill = false;
             pentaKill = false;
 
         }
         if (quadKill)
         {
             doubleKill = false;
             tripleKill = false;
             pentaKill = false;
 
         }
         if (pentaKill)
         {
             doubleKill = false;
             tripleKill = false;
             quadKill = false;
 
         }
     }
 }

How can I make it so I can reset the timer back to it's default timer 5f without stopping the counting down?

I tried this:


  if(chainKills == 2)
                 {
                     doubleKill = true;
 
                  killTimer = 5;
                  killTimer -= speed * Time.deltaTime;
                     
                     
     
     
                 }


However that simply hard-codes killTimer to 5 and will not count down like I'd like it. Please share your unity expertise with a aspiring novice!

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

2 Replies

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

Answer by xxmariofer · Feb 05, 2019 at 07:50 PM

well thats a really overenginered solution and a bit hard to understand. setting the value to 5 will never stop the countdown, so what is stopping the countdown is something else. first you need to remove the killchain = true inside the multplier method since thats a bug 100%, whats the kills value? it is set in the inspector? is there any extra code you are not sharing? since if kills and prevkills are not being updated and the killchain is always true is not posible that just after setting killtimer = 5; the countdown stops.

Comment
Add comment · Show 7 · 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 lbryan212 · Feb 05, 2019 at 08:02 PM 0
Share

Everything in this code is working correctly, the kills comes from my Game$$anonymous$$anager script which isn't attached. The only thing not working in this over complicated mess is how to reset the timer. For example once I get a kill, kill chain is true as long as the kill timer > 0. So if I now get a double kill within the 5 seconds, I'd like the timer to start back at 5 and count down again without resetting the kill chain bool

avatar image lbryan212 lbryan212 · Feb 05, 2019 at 08:10 PM 0
Share

The reasoning for having the kill chain bool is because when the player gets a kill, killChain is true. While killChain is true, prev$$anonymous$$ills will not be updated until killChain is false, then prev$$anonymous$$ills will equal kills. This is done so i can detect how many kills the player is getting during the combo.

avatar image xxmariofer lbryan212 · Feb 05, 2019 at 08:41 PM 0
Share

yes, but you are doing this, i promise you you can just delete killChain and will make no difference :)

 killChain = true;
 if (killChain)
 {
      killTimer -= speed * Time.deltaTime;
  }

comparing kill chain there makes no sense, cause it will alway be true (you are setting it to true just before comparing it), in the exact same point you are setting up your kills value (in the other script), set up your killTimer = 5; and tell me if that didnt work :)

Show more comments
avatar image lbryan212 · Feb 05, 2019 at 08:19 PM 0
Share

https://imgur.com/a/JRqNbkN


This is my script in action, as you can see the kills do populate and prev$$anonymous$$ills updates after the killChain bool is false.

avatar image
0

Answer by lbryan212 · Feb 05, 2019 at 07:46 PM

While visiting the toilet I believe I found the answer to my question.

 public float killTimer;
 public float maxTimer;
 public float diffrenceTimer;
 
   
 
 diffrenceTimer = maxTimer(5) - killTimer(whatever it is)
 

 
 killTimer = killTimer + diffrenceTimer;
 
 
 
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

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

Trigger a Timer 2 Answers

Farming game Time management 0 Answers

Increase a value by one every minute 2 Answers

Milliseconds Timer Question 1 Answer

How to slow down my timer script? 0 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