- Home /
Changing background according to local time
I have 3 backgrounds; sunrise, afternoon and night. What I want to achieve is change them according to the local time of the device. I learned about System.DateTime.Now, so I thought about using variables and "if's" to store delimited hours to "choose" which background would appear.
My problem is that I'm really lost about how to switch between them. Like, how to pick the actual background, destroy it, change it to the next one and so on.
Thank you for your time. If there's also an easier way to do this (or even a tutorial that I overlooked) I would appreciate it knowing, maybe I'm complicating things too much.
Assu$$anonymous$$g your background is to be loaded into an Image or SpriteRenderer component, create an array of sprites and mark it either public or private with the [SerializeField] attribute, start an InvokeRepeating or a Coroutine with a relatively long interval (but less than one hour), add a switch statement that tests DateTime.Now.Hour, and pick the image stored in the array at index DateTime.Now.Hour - 1 if you have 24 images. If you have less, you'll have to use a bit more logic to get the right image.