SHARE
TWEET

Untitled

a guest Oct 21st, 2019 81 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. using UnityEngine;
  2. using System;
  3.  
  4. public class SwitchCase : MonoBehaviour
  5. {
  6.     private string timeOfTheDay;
  7.     private int hourToSwitch = 7;
  8.     DateTime dateTime = DateTime.Now;
  9.  
  10.     void Update()
  11.     {
  12.         //CheckTimeWithIfElse();
  13.         CheckTimeWithConditionalOperator();
  14.     }
  15.     private void CheckTimeWithIfElse()
  16.     {
  17.         if(dateTime.Hour > hourToSwitch )
  18.         {
  19.             timeOfTheDay = "day";
  20.             Debug.Log(timeOfTheDay);
  21.         }
  22.         else
  23.         {
  24.             timeOfTheDay = "night";
  25.             Debug.Log(timeOfTheDay);
  26.         }
  27.     }
  28.     private void CheckTimeWithConditionalOperator()
  29.     {
  30.         timeOfTheDay = (dateTime.Hour > hourToSwitch) ? "day" : "night";
  31.         Debug.Log(timeOfTheDay);
  32.     }
  33. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top