Advertisement
ensiferum888

SeasonControl

Jul 18th, 2013
419
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.38 KB | None | 0 0
  1. using UnityEngine;
  2. using System.Collections;
  3. using System.Threading;
  4.  
  5. public class SeasonControl: MonoBehaviour {
  6.    
  7.     public int currentYear;
  8.     public float globalTimer;
  9.     public float seasonTimer;
  10.     public bool realtimeTesting = false;
  11.    
  12.     private CustomTerrainScriptAtsV3Snow snowScript;
  13.    
  14.     public enum Season{
  15.         Spring = 0,
  16.         Summer,
  17.         Fall,
  18.         Winter
  19.     }
  20.    
  21.     public Season currentSeason;
  22.  
  23.     // Use this for initialization
  24.     void Start () {
  25.         snowScript = GameObject.FindGameObjectWithTag("ActTerrain").GetComponent<CustomTerrainScriptAtsV3Snow>();
  26.     }
  27.    
  28.     // Update is called once per frame
  29.     void Update () {
  30.         if(!realtimeTesting)
  31.         {
  32.             if(Input.GetKeyDown(KeyCode.U))
  33.             {
  34.                 triggerWinter();
  35.             }
  36.             if(Input.GetKeyDown(KeyCode.I))
  37.             {
  38.                 triggerSummer();   
  39.             }
  40.             return;
  41.         }
  42.         globalTimer += Time.deltaTime;
  43.         if(globalTimer > 0 && globalTimer % seasonTimer == 0)
  44.         {
  45.             triggerSeasonChange();
  46.             globalTimer = 0;
  47.         }
  48.     }
  49.    
  50.     private void triggerSeasonChange()
  51.     {
  52.         int seasonIndex = (int)currentSeason;
  53.         seasonIndex++;
  54.         if(seasonIndex > 3)
  55.         {
  56.             seasonIndex = 0;   
  57.             currentYear++;
  58.         }
  59.        
  60.         currentSeason = (Season)seasonIndex;
  61.     }
  62.    
  63.     public void triggerSummer()
  64.     {
  65.         snowScript.triggerng = true;
  66.         snowScript.triggerSnow = false;
  67.     }
  68.    
  69.     public void triggerWinter()
  70.     {
  71.         snowScript.triggerng = true;
  72.         snowScript.triggerSnow = true;
  73.     }
  74. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement