Guest User

http://stackoverflow.com/questions/36013265/stop-co-routine-

a guest
Mar 15th, 2016
87
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.42 KB | None | 0 0
  1. using UnityEngine;
  2. using System.Collections;
  3.  
  4. public class thermoPowerControlPanel : MonoBehaviour
  5. {
  6.     public bool t1 = true;
  7.     public int temperature;
  8.     private int tempUp = 10;
  9.     private int tempDown = 1;
  10.  
  11.     public thermoPowerControlPanel()
  12.     {
  13.         temperature = 100;
  14.     }
  15.  
  16.     public void turbine1State(bool t1)
  17.     {
  18.  
  19.         if (t1 == false)
  20.         {
  21. //        ThermoElectric.t1Bool = t1;
  22.             Debug.Log(t1);
  23.             StopCoroutine("increaseTemperature");
  24.             StopCoroutine("decreaseTemperature");
  25.             StartCoroutine("decreaseTemperature");
  26.         }
  27.  
  28.         if (t1 == true)
  29.         {
  30. //            ThermoElectric.t1Bool = t1;
  31.             Debug.Log(t1);
  32.             StopCoroutine("increaseTemperature");
  33.             StopCoroutine("decreaseTemperature");
  34.             StartCoroutine("increaseTemperature");
  35.         }
  36.     }
  37.  
  38.     public IEnumerator decreaseTemperature()
  39.     {
  40.         for (int i = 0; i < temperature; i++)
  41.         {
  42.             yield return new WaitForSeconds(1.0f);
  43.             temperature = temperature - tempDown;
  44.             Debug.Log(temperature);
  45.         }
  46.     }
  47.  
  48.     public IEnumerator increaseTemperature()
  49.     {
  50.         for (int i = 0; i < 100 - temperature; i++)
  51.         {
  52.             yield return new WaitForSeconds(1.0f);
  53.             temperature = temperature + tempUp;
  54.             Debug.Log(temperature);
  55.         }
  56.     }
  57. }
Add Comment
Please, Sign In to add comment