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 BraydenYates · Jun 14, 2013 at 03:04 AM · variableintegersubtract

Subtract from Integer

Hello. I have tried for quite some time to get this working, but I can't. How can I subtract from an integer every 60 seconds in case a gameobject is right clicked? If said object is right clicked, it refills back to 100. All help is appreciated.

Comment
Add comment · Show 2
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 bodec · Jun 14, 2013 at 03:45 AM 0
Share

set up a timer and when timer is greater than setTime int- x amount then reset timer on a click int equals x amount

avatar image SinisterRainbow · Jun 16, 2013 at 10:50 PM 0
Share

You should select an answer so this question doesn't remain open, or add comments back if it's still unclear.

3 Replies

· Add your reply
  • Sort: 
avatar image
1

Answer by theAfrican · Jun 14, 2013 at 04:37 AM

     function Start()    
     {    
        StartCoroutine("DoEvent");    
     }
     
      
     
     function DoEvent()    
     {    
           yield WaitForSeconds(1);
 // do integer subtraction here
           StartCoroutine("DoEvent");
     }

for the right click you can handle that in an onmouse event

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 SinisterRainbow · Jun 14, 2013 at 04:53 AM 0
Share

someone gave you a thumbs down, I don't know why, thumbs down should only be for incorrect statements, so I gave it a thumbs up. it's essentially fine except it's not called every 60 seconds like he wanted, and that's trivial.

avatar image
0

Answer by SinisterRainbow · Jun 14, 2013 at 04:50 AM

I created a separate class with static functions for timers, and I recommend you do so as well. Using callbacks with startcoroutine I find is the best way. Make sure it inherits from monobehaviour). This example below subtracts y from x for 60 seconds. If you are careful, you can call the _SetTimer(..) again inside the subtract function so it's called everytime.

 public class YourClass : monobehaviour {
 
 private int x;
 private int y;
 
 private IEnumerator _SetNewTimer( float fDelay, System.Action callBack ) {
         yield return new WaitForSeconds( fDelay );
         if ( callBack != null )
             callBack();
     }
 
 
 private void _DoSubtract() {
    x -= y;
 }
 ...
 private void SomeFunction() {
   ...
   StartCoroutine(_SetNewTimer(60.0f,_DoSubtract));
   ...
 }
 ...
 } //end class
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
avatar image
0

Answer by umangindianic · Jun 14, 2013 at 08:53 AM

First create Timer for 60 seconds and check the if timer is equal to 60 seconds subtract the value at the same time and if it is right clicked that refill the value with 100. same thing you can update n number of times.

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

18 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

Related Questions

Why can't won't my if then statements work? 1 Answer

Detecting multiples of 2 3 Answers

Decrease int variable over time 4 Answers

Playerprefs across Scenes 1 Answer

Subtract variable value in certain seconds 1 Answer


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