Change photo with every hour automatically
Hey, i want a lens in which the photo changes automatically every hour for example at 10pm it shows image 1 and at 11pm it shows image 2 and as such.
Can anyone help me with a script which can help me do this
i know it is possible becuase i have seen time scrpit which changes time image with script.
Thanks!
Hi!
First you need the current hour as a number (so for example at 22:54 it would return 22). In Javascript, you can simply call
Then, make an array of textures to pick from, and use that 'currentTime' variable as the index:
And then to set the texture to an Image Component, use:
Here's the full code including the inputs to use in the Inspector:
And this is a screenshot of that script (taken at 22:51 my time), so only the 22nd texture has to be filled to see it in the preview:
Max van Leeuwen Hey thanks but your scripts shows 1 image in a hour. Is there any way i can add minutes too because i want let say image 1 from 8pm to 8:30pm and image 2 from 8:50pm to 9:24pm.
i basically want script with custom time that i can edit myself to change time
Yeah! The new Date() class has many options, you can see all of them on this page!
For example, for the current minute of the hour, use
Which you could then use, for example, to check if it's between 0-30 or 30-60
If you want a lot of time slots at specific dates, this method would get a bit annoying to work with.
In that case, I'd advice making a table of epoch times of all the time points you have!
Epoch times are timezone-independent, it is the amount of milliseconds since January 1st, 1970, 00:00:00UTC.
So it gives you a really long number, like '1649368198' (this is the time as I'm currently writing this).
If you use Date.now(), you get the time in epoch format, so checking if another epoch time is in the past or in the future is just a matter of checking if it is lesser or greater than it!
You can use this website to convert 'human readable' times to epoch format.
Hope this helps!
Max van Leeuwen
thanks for this epoch method but this will only work for 1 day so is there any universal method that can work everyday and if yes then can you please provide me the full script as you did in the 1st reply
btw i saw a script somewhere in which the made difference case that helped them to achieve this can we also do the same?
Also can i know any of your social username or your email so that i can contact you in case i want further help?