Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 14 Next capture
2021 2022 2023
2 captures
12 Jun 22 - 14 Jun 22
sparklines
Close Help
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
  • Help Room /
avatar image
0
Question by KnightRiderGuy · Jan 13, 2016 at 04:12 PM · c#scripting beginnerdatetime

Check If System Month IS Between A Certain Range

I'm working on using some if statement to check if the system month is between a certain range to sort of compensate for daylight savings times.

 if (sysMonth == 01) {
                 yield return new WaitForSeconds (0.5f); // wait time
                 VoiceBox VBbr = FindObjectOfType<VoiceBox> ();
                 VBbr.BrightnessDetected ();
 
                 MessageCentreManager MCMbd = FindObjectOfType<MessageCentreManager> ();
                 MCMbd.GoBrightnessDetectedMessage ();
                 print ("Brilliant Light Detected Michael");
             }

Something like that. I'm wondering if I'm on the right track and I need something like:

 if (sysMonth >=10 && sysMonth <= 02)  //October to Feb.

Am I on the right track with that or way off the mark? I always have a hard time wrapping my head around that stuff ;)

Comment
Add comment · Show 7
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image KnightRiderGuy · Jan 13, 2016 at 09:51 PM 0
Share

I think this is the end result I'm looking for? It's a real "Brain Baker" but I think it's logical? Correct me if I'm wrong. ;)

 //Send Brightness Detected Audio Resoponse Request to Voice Box Object
     IEnumerator BrightnessResponse(){
         //Check System Time if its between 5P$$anonymous$$ - 7A$$anonymous$$ then play message
         if (sysHour >= 17 && sysHour <= 7) {
             //Check $$anonymous$$onths For Winter
             if (sys$$anonymous$$onth >= 01 && sys$$anonymous$$onth <= 10) {
                 yield return new WaitForSeconds (0.5f); // wait time
                 VoiceBox VBbr = FindObjectOfType<VoiceBox> ();
                 VBbr.BrightnessDetected ();
                 //Send $$anonymous$$essage for $$anonymous$$essage Centre to display "BRHT LGHT DETECTED" message
                 $$anonymous$$essageCentre$$anonymous$$anager $$anonymous$$C$$anonymous$$bd = FindObjectOfType<$$anonymous$$essageCentre$$anonymous$$anager> ();
                 $$anonymous$$C$$anonymous$$bd.GoBrightnessDetected$$anonymous$$essage ();
                 print ("Brilliant Light Detected $$anonymous$$ichael - WINTER AT NIGHT");
             }
         }
 
         //Summer $$anonymous$$onths Time Check
         //Check System Time if its between 5A$$anonymous$$ - 9P$$anonymous$$ then play message
         if (sysHour >= 21 && sysHour <= 5) {
             //Check $$anonymous$$onths For Summer
             if (sys$$anonymous$$onth >= 03 && sys$$anonymous$$onth <= 09) { //$$anonymous$$ar. to Sept.
                 yield return new WaitForSeconds (0.5f); // wait time
                 VoiceBox VBbr = FindObjectOfType<VoiceBox> ();
                 VBbr.BrightnessDetected ();
                 //Send $$anonymous$$essage for $$anonymous$$essage Centre to display "BRHT LGHT DETECTED" message
                 $$anonymous$$essageCentre$$anonymous$$anager $$anonymous$$C$$anonymous$$bd = FindObjectOfType<$$anonymous$$essageCentre$$anonymous$$anager> ();
                 $$anonymous$$C$$anonymous$$bd.GoBrightnessDetected$$anonymous$$essage ();
                 print ("Brilliant Light Detected $$anonymous$$ichael - SU$$anonymous$$$$anonymous$$ER AT NIGHT");
             }
         }
     }
 
     //Send Darkness Detected Audio Resoponse Request to Voice Box Object
     IEnumerator DarknessResponse(){
         //Check System Time if its between 7Am - 5P$$anonymous$$ then play message
         if (sysHour >= 7 && sysHour <= 17) {
             //Check $$anonymous$$onths For Winter
             if (sys$$anonymous$$onth <= 02 && sys$$anonymous$$onth <= 10) { //Feb. to Oct.
                 yield return new WaitForSeconds (0.5f); // wait time
                 VoiceBox VBdr = FindObjectOfType<VoiceBox> ();
                 VBdr.DarknessDetected ();
                 //Send $$anonymous$$essage for $$anonymous$$essage Centre to display "A$$anonymous$$B LGHT INSUF" message
                 $$anonymous$$essageCentre$$anonymous$$anager $$anonymous$$C$$anonymous$$dd = FindObjectOfType<$$anonymous$$essageCentre$$anonymous$$anager> ();
                 $$anonymous$$C$$anonymous$$dd.GoDarknessDetected$$anonymous$$essage ();
                 print ("Darkness $$anonymous$$ust Not Be Naturally Occuring $$anonymous$$ichael - WINTER AT DAY");
             }
         }
 
         //Summer $$anonymous$$onths Time Check
         //Check System Time if its between 5Am - 9P$$anonymous$$ then play message
         if (sysHour >= 5 && sysHour <= 21) {
             //Check $$anonymous$$onths For Summer
             if (sys$$anonymous$$onth >= 03 && sys$$anonymous$$onth <= 09) { //$$anonymous$$ar. to Sept.
                 yield return new WaitForSeconds (0.5f); // wait time
                 VoiceBox VBdr = FindObjectOfType<VoiceBox> ();
                 VBdr.DarknessDetected ();
                 //Send $$anonymous$$essage for $$anonymous$$essage Centre to display "A$$anonymous$$B LGHT INSUF" message
                 $$anonymous$$essageCentre$$anonymous$$anager $$anonymous$$C$$anonymous$$dd = FindObjectOfType<$$anonymous$$essageCentre$$anonymous$$anager> ();
                 $$anonymous$$C$$anonymous$$dd.GoDarknessDetected$$anonymous$$essage ();
                 print ("Darkness $$anonymous$$ust Not Be Naturally Occuring $$anonymous$$ichael - SU$$anonymous$$$$anonymous$$ER AT DAY");
             }
         }
     }
avatar image Dave29483 · Jan 14, 2016 at 06:30 PM 0
Share

Your if statements are a bit screwy.

 if (sys$$anonymous$$onth <= 2 && sys$$anonymous$$onth <= 10) will only ever be true for values <= 2
     
     Should be (>= 2 && <= 10) so the value you are looking for is greater than or equal to your lowest value 2 and less than or equal to your highest value 10.




avatar image KnightRiderGuy Dave29483 · Jan 16, 2016 at 02:26 PM 0
Share

Thanks @Dave29483, Yeah when come to figuring out the correct values for the month range I want I get really messed up for some reason. Now if I change it to this:

(sys$$anonymous$$onth >= 2 && sys$$anonymous$$onth <= 10) { //Jan. to Oct.*/

I don't get my darkness response firing, correct me if I'm wrong but is that not because the first part thinks I want the system month to be greater than 2 (Feb.) when it is currently 1 (Jan.) I would have thought this would be right:

(sys$$anonymous$$onth <= 2 && sys$$anonymous$$onth <= 10) { //Jan. to Oct.*/

Because then System month is less but equal to 2 (Below Jan & Feb.)?? Ahh this stuff bakes my brain lol

$$anonymous$$eep in $$anonymous$$d I'm up here in Canada so you might be getting the month times confused ;)

avatar image Danixos · Jan 16, 2016 at 04:34 PM 1
Share

Why not use DateTime?

 if (DateTime.Now.IsDaylightSavingTime())
 {
     // Shenanigans!
 }
avatar image KnightRiderGuy Danixos · Jan 16, 2016 at 07:41 PM 0
Share

Oh hey @$$anonymous$$nemotic, thanks I was not aware I could even do that. lol now I'm not sure how I would integrate that into what I have here, can you give a simple example and then I can take the ball and run with it, lol ball not scissors ;)

avatar image Danixos KnightRiderGuy · Jan 16, 2016 at 10:16 PM 0
Share

See my answer. :)

Show more comments

2 Replies

· Add your reply
  • Sort: 
avatar image
1

Answer by Danixos · Jan 16, 2016 at 10:15 PM

You can determine whether DST is active in the current time zone by calling DateTime.Now.IsDaylightSavingTime(). It returns true if DST is active. You can find DST delta (that is, how much time is advanced when DST is active) by accessing TimeZone.CurrentTimezone.GetDaylightChanges(DateTime.Now.Year).Delta. All this is from System namespace.

 DateTime now = DateTime.Now;
 TimeZone tz = TimeZone.CurrentTimeZone;
 TimeSpan delta = tz.GetDaylightChanges(now.Year).Delta;
 
 bool isDST = now.IsDaylightSavingTime();

Then you can make your adjustments based on this.

HTH

Comment
Add comment · Show 3 · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image KnightRiderGuy · Jan 16, 2016 at 11:03 PM 0
Share

Thanks @$$anonymous$$nemotic, it's going to take me a little time to figure that out but that looks awesome! I had no idea I could do that in Unity :)

avatar image Danixos KnightRiderGuy · Jan 16, 2016 at 11:13 PM 1
Share

You're welcome. :) Take a peek into standard .NET namespaces whenever your trying to solve a problem that isn't gamedev-specific. There's a lot of good stuff in there.

avatar image KnightRiderGuy Danixos · Jan 16, 2016 at 11:23 PM 0
Share

Awesome @$$anonymous$$nemotic I'll do that. I just need to figure out how to work this into what I have, I think I have an idea but I'll see... ;)

avatar image
0

Answer by KnightRiderGuy · Jan 16, 2016 at 03:57 PM

I wonder if what I need is to use the || "or" instead of && "Or" and so that the argument is something like:

 (sysMonth <= 2 || sysMonth >= 10) { //Jan. to Oct.

So that System Month is Less or equals to 2 (less than or equals to February) OR System month is greater than or equals to 10 (October) That way system month has to be greater than 10 to be beyond or past October? Maybe I'm not fully understanding it right but in my head that sound logical, Am I baked in assuming that?

Comment
Add comment · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users

Your answer

Hint: You can notify a user about this post by typing @username

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this Question

Answers Answers and Comments

61 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

How can i run a script with a single key press? 1 Answer

Having transitions between two VideoPlayers triggered by clicking "x" times in a text layer 0 Answers

How to add a editing option to variables in a script in Inspector? 0 Answers

trying to fade alpha based on the Y angle using a range so every 90 degrees the material changes but fades back n forth 0 Answers

How to make a random object generator that responds to simple touch? 0 Answers


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges