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 carlqwe · May 16, 2015 at 04:00 PM · guicolliderint

Int, Colliders, and GUI

So here's my script i gonna add some feelings and other stuff that the player expresses. So here i want my "warm" int to be higher every secound IF im not in one of the shadows colliders. Then if i am inside of one, the "warm" int is going to be get lower. It's also displayed on the screen. But here's the problem, the "warm" int never change. And i even set it to 50 in the begining. Help please! ~carlqwe

Code: #pragma strict

 var warm : int = 50;
 
 function Update ()
 {
 
 }
 
 function OnTriggerStay (Col : Collider)
 {
     if(!Col.tag == "shadows")
     {
         warm += 1 * Time.deltaTime;
     }
     else
     {
         warm -= 2 * Time.deltaTime;
     }
 }
 
 function OnGUI ()
 {
     GUI.Label(new Rect(780, 680, 250, 100), warm.ToString(""));
 }
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
1
Best Answer

Answer by Baste · May 16, 2015 at 09:56 PM

Warm is an integer. You're adding 1 * Time.deltaTime to it - which is a float. That float will be rounded to an integer before it's added to the warm variable. In all of the languages used in Unity, rounding is always towards zero.

So, your 1 * Time.deltaTime is somewhere in the realm of 0.01 or lower, so you're actually never adding (or subtracting) anything from the warm variable. The easiest solution is to just change the warm variable to a float. When you're printing it, you should probably cast it back to an integer, so it doesn't print all of the decimal places.

Comment
Add comment · Show 3 · 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 carlqwe · May 17, 2015 at 12:06 PM 0
Share

Okay thank you, but if u where to change my script so it worked how whould you do it?

avatar image barbe63 · May 17, 2015 at 01:48 PM 0
Share

As he said, just change the int to float like this:

  var warm : float = 50;
avatar image carlqwe · May 17, 2015 at 02:53 PM 0
Share

I did indeed and it worked thank you very much!

avatar image
0

Answer by Multifred · May 17, 2015 at 03:10 PM

the reason it never change is that your field warm is an integer: 1*Time.deltaTime is lower than 1 so it's as if you added 0

change warm into a float and create a GetWarm function that return (int)warm;

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

20 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

Related Questions

iTween colliders 1 Answer

GUI Text to GUI Label Script? 1 Answer

Counter with a Rounded GUI bar 1 Answer

Arrange ints from biggest to smallest and display them in a table 1 Answer

i cant make a label show my var Health : int = 100; 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