Advertisement
DanilaI

Wallpaper

Sep 17th, 2023
760
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.03 KB | None | 0 0
  1. using System;
  2. using UnityEngine;
  3. using UnityEngine.UI;
  4.  
  5. public class WallpaperChanger : MonoBehaviour
  6. {
  7.     public Texture[] wallpapers;
  8.     private RawImage wallpaperImage;
  9.  
  10.     private void Start()
  11.     {
  12.         wallpaperImage = GetComponent<RawImage>();
  13.         UpdateWallpaper();
  14.     }
  15.  
  16.     private void Update()
  17.     {
  18.  
  19.         DateTime currentTime = DateTime.Now;
  20.  
  21.  
  22.         int hour = currentTime.Hour;
  23.  
  24.         if (hour >= 5 && hour < 12)
  25.         {
  26.             SetWallpaper(0);
  27.         }
  28.         else if (hour >= 12 && hour < 18)
  29.         {
  30.             SetWallpaper(1);
  31.         }
  32.         else if (hour >= 18 && hour < 21)
  33.         {
  34.             SetWallpaper(2);
  35.         }
  36.         else
  37.         {
  38.             SetWallpaper(3);
  39.         }
  40.     }
  41.  
  42.     private void UpdateWallpaper()
  43.     {
  44.         Update();
  45.     }
  46.  
  47.     public void SetWallpaper(int index)
  48.     {
  49.  
  50.         if (index >= 0 && index < wallpapers.Length)
  51.         {
  52.             wallpaperImage.texture = wallpapers[index];
  53.         }
  54.     }
  55. }
  56.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement