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 LikeShiSui · Nov 28, 2014 at 11:08 PM · javascriptgui

Temperature Script?

Anyone have a basic script outline of a temperature meter (a GUI starting with 98 degrees and steadily decreasing or increasing), and can change temperature when in range of a specific object (i.e: a campfire for warmth)?

If someone could outline a script that starts me off, that'd be absolutely great. Thanks!

Comment
Add comment · Show 1
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 LikeShiSui · Nov 28, 2014 at 11:10 PM 0
Share

Yeah, only thing is, I'm not sure what GUI to use and the variables either, I've never really handled this sort of situation before.

3 Replies

· Add your reply
  • Sort: 
avatar image
1

Answer by getyour411 · Nov 28, 2014 at 11:08 PM

 OnTriggerEnter () {
 yourTemp++;
 }

 OnTriggerExit() {
 yourTemp--;
 }

Comment
Add comment · Show 2 · 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 LikeShiSui · Nov 28, 2014 at 11:12 PM 0
Share

How to make it decrease over time?

avatar image getyour411 · Nov 28, 2014 at 11:19 PM 0
Share

Search for any number of examples here that include a timer/ti$$anonymous$$g element and do some maths based on the relative warm-up/cool down you want;

avatar image
0

Answer by Kiwasi · Nov 28, 2014 at 11:21 PM

Temperature will move closer to the surrounding temperature over time. For a rather crude approximation I would do the following.

  • Create a script that records the temperature of each GameObject

  • Use a sphere cast at some defined frequency, or use OnTriggerStay, to get the temperature of all nearby GameObjects

  • Adjust the temperature closer to the average of all the temperatures of nearby objects

  • You could also define an ambient temperature to use if no GameObjects are close

For an accurate approximation grab a university level physics or engineering textbook, and look up the chapter on thermodynamics and heat transfer. This is not a light topic, I'd suggest running with an approximation rather then trying to create accurate temperature physics.

Comment
Add comment · Show 2 · 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 LikeShiSui · Nov 28, 2014 at 11:24 PM 0
Share

The temperature script that I am looking for goes like this. Start off at a certain degree, and -1 degree after every 20-30 seconds or something like that. When you get in a radius of a certain gameObject, rise up +1 every 10-15 seconds or so. Hopefully that helps you a little more with your thinking.

avatar image Kiwasi · Nov 29, 2014 at 09:00 AM 0
Share

Lol, not my project, not my thinking. The model you describe is not accurate.

However I can $$anonymous$$dlessly write out a script that does that for you.

 public class Temperature : $$anonymous$$onoBehaviour {
     public float temperature {get; private set}
 
     void Start (){
         StartCoroutine(Cool());
     }
 
     void OnTriggerEnter (collider other){
         StartCoroutine ("Heat");
     }
 
     void OnTriggerExit (collider other){
         StopCoroutine ("Heat");
     }
 
     IEnumerator Cool (){
         while (true){
             yield return new WaitForSeconds(30);
             temperature -= 1;
         }
     }
 
     IEnumerator Heat (){
         while (true){
             yield return new WaitForSeconds(10);
             temperature += 1;
         }
     }
 
 }


avatar image
0

Answer by dkaloger · Sep 11, 2020 at 04:29 PM

i know this is a very old question but i think this code snipet works perfectly

 using System.Collections;
 using System.Collections.Generic;
 using UnityEngine;
 
 public class temp : MonoBehaviour
 {
     public float sc1 =3f; //specific heat capacity
     public float sc2 = 6f;
     public float sm1 = 100f; //mass
     public float sm2 =200f;
     public float sk1=0.609f;//insulation
     public float sk2 = 0.58f;
     public float tickspeed = 0.25f;
     public float surfacearea = 25;
     float C1; // heat capacity
     float C2;
 
     public float T1 = 370f; // temperature in kelvin
     public float T2 = 315f;
      float ΔQ;
      float Q1;
      float Q2;// thermal energy
     // Start is called before the first frame update
     void Start()
     {
    
     }
 
     // Update is called once per frame
     void FixedUpdate()
     {
  
         C1 = sc1 * sm1;
         C2 = sc2 * sm2;
         ΔQ = tickspeed * Mathf.Min(sk1, sk2) * (T1 - T2) * surfacearea * surfacearea; 
         T1 = T1 - ΔQ / C1;
         T2 = T2 + ΔQ / C2;
         Q1 = C1 * T1;
         Q2 = C2 * T2;
     }



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 ShadyProductions · Sep 11, 2020 at 11:14 PM 0
Share

What's with the weird Δ symbols, does that even compile?

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

5 People are following this question.

avatar image avatar image avatar image avatar image avatar image

Related Questions

Setting Scroll View Width GUILayout 1 Answer

If statement only work once? 1 Answer

Can someone help me fix my Javascript for Flickering Light? 6 Answers

The name 'Joystick' does not denote a valid type ('not found') 2 Answers

GUI button not showing up 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