Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using UnityEngine;
- using UnityEngine.UI;
- public class WallpaperChanger : MonoBehaviour
- {
- public Texture[] wallpapers;
- private RawImage wallpaperImage;
- private void Start()
- {
- wallpaperImage = GetComponent<RawImage>();
- UpdateWallpaper();
- }
- private void Update()
- {
- DateTime currentTime = DateTime.Now;
- int hour = currentTime.Hour;
- if (hour >= 5 && hour < 12)
- {
- SetWallpaper(0);
- }
- else if (hour >= 12 && hour < 18)
- {
- SetWallpaper(1);
- }
- else if (hour >= 18 && hour < 21)
- {
- SetWallpaper(2);
- }
- else
- {
- SetWallpaper(3);
- }
- }
- private void UpdateWallpaper()
- {
- Update();
- }
- public void SetWallpaper(int index)
- {
- if (index >= 0 && index < wallpapers.Length)
- {
- wallpaperImage.texture = wallpapers[index];
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement