Timed Events Such As Holidays?

If I were to place certain objects such as christmas lights on a building (or a tree) and put them all under a parent gameobject and turn that object off, in script is it possible to set up a timer so only in December will it show up?

I would like to do this for a variety of things like menu text and other models and effects, if this is possible could someone assist in setting this up?

You can use functions provided by .Net ; System.DateTime.Now, for example.

1 Like

This looks kinda like what we are looking for, but I’m not sure how to implement it, I need to provide 2 dates and have it only active when the date is between the two set

Why don’t you use Google ?

that doesn’t really help much, it seems very enigmatic to me, I am not used to doing things with the system in code.

Seems hard to test, you have to wait for the appropriate dates lol

I don’t understand why you think this is hard…

        public DateTime christmasTime = new DateTime(DateTime.Now.Year, 12, 25);
        public DateTime easterTime = new DateTime(DateTime.Now.Year, 4, 20);

void Start() {
            DateTime startChrismas = christmasTime.AddDays(-10);
            DateTime endChrismas = christmasTime.AddDays(10);

            myChristmasGameObjects.SetActive(DateTime.Now.Ticks > startChrismas.Ticks && DateTime.Now.Ticks < endChrismas.Ticks);
}

…

1 Like

Thanks so much, it works, just not sure how.

What are the numbers?
I am guessing 12 is the month and 25 being the day, but easter isn’t on the 20th of April, and what are the -10 and 10 things?

Documentation DateTime. So yes, 12 is the month and 25 the day. There are other constructors available.

Easter WAS on the 20th April 2014 : List of dates for Easter.

About AddDays, like it says, it add days depending on the DateTime variable. I did that because I think you wanna show the Christmas things for several days, not for only one day. It means “Active all christmas gameObjects from 15th December 2014 to 4th January 2015”. It’s just an example, but you can do whatever you want.

Ahh, sorry I’m still thinking Easter is in March :sweat_smile:

Thanks for explaining how it all works, makes much more sense now, thanks :smile: