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
1
Question by darkironphoenix · May 28, 2012 at 08:53 AM · timevaluedecrease

Reducing a value over time

Ok, read a few questions, haven't managed to get anything to work.

I have a system set up so when someone leaves a building, their body temp should decrease over time, using a modifiable variable. Everything i try so far either leaves it not working at all, or defaulting to frames rather than seconds. I'm using js. Below is the relevant lines from my current code, with my last attempt at getting it to work.

 var bodytemp : float = 20.0;
 var heatloss : float = 0.1;
 var playeroutside : boolean = false;

 if (playeroutside){
          InvokeRepeating("bodytempmody", 2, 20);
     }

 function bodytempmody (){
 
 bodytemp -= heatloss;
 }

Any thing anyone can suggest is much appreiciated.

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 BiG · May 28, 2012 at 08:57 AM

Try this:

 var bodytemp : float = 20.0;
 var heatloss : float = 0.1;
 var playeroutside : boolean = false;
 var function_lock = false;

 function Update(){
    if (playeroutside && !function_lock){
       function_lock = true;
       bodytempmody();
    }
 }
 
 function bodytempmody(){
    yield WaitForSeconds(2);
    bodytemp -= heatloss;
    function_lock = false;
 }
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 darkironphoenix · May 28, 2012 at 09:15 AM 1
Share

That worked perectly, thank you :)

avatar image
2

Answer by Alismuffin · May 28, 2012 at 09:04 AM

Maybe you could use Time.deltaTime? (Time passed since last frame). This should give you a steady decrease of 0.1 to bodytemp each second

Untested however so I could be wrong

  var bodytemp : float = 20.0;
     var heatloss : float = 0.1;
     var playeroutside : boolean = false;
     
     if(playeroutside){
     bodytemp -= heatloss*Time.deltaTime;
     }
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 Alismuffin · May 28, 2012 at 09:28 AM 0
Share

Oh and of course you have to wrap all but the variables in the Update function

I tested it now and works fine If you wish it to go down 1 value per second, simply change the variable of heatloss to 1. It will count down in seconds.

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

6 People are following this question.

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

Related Questions

slowly decrease value when in trigger 1 Answer

TimeSpan why are you being difficult? 2 Answers

Need help with value over time! 1 Answer

Static Variable Doesn't Change ? 0 Answers

Variable that decreases after a certain amount of time? 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