Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 12 Next capture
2021 2022 2023
1 capture
12 Jun 22 - 12 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 /
This question was closed Jan 09, 2016 at 05:36 PM by KnightRiderGuy for the following reason:

The question is answered, right answer was accepted

avatar image
0
Question by KnightRiderGuy · Jan 09, 2016 at 03:10 PM · c#if-statementscodepagecase

Combine If Statement Conditions

I changed the title after some Googling. But Yesterday I was toying around with the idea of having my if statement in my Switch case not only do something when the light slider reached a certain value but also only if the time on the computer was between a certain time of day. I was looking into I think it's called "Nested" if Statements? Not sure if that is what I should be looking at, but my head has been just spinning with ideas for combining the LDR Input and cross referencing that with Temperatures data, time of day and so one to execute different responses based on different values... had no idea sos much of this was possible.

I commented out the part I was experimenting with. It did not give me any console errors but did not work so I must be using it wrong although I thought I was on the right track with it??

 (slider.value > 0.9f && oldValue <= 0.9f & sysHour >= 15 && sysHour <= 06) //Voice Will Only Activate between 6PM & 6AM

This part has more of the code block I was playing around with.

 // else check if we need to play a sound and do it
             if (slider.value > 0.9f && oldValue <= 0.9f) //This will call the voice no matter what time of day or night it is
                 //(slider.value > 0.9f && oldValue <= 0.9f & sysHour >= 15 && sysHour <= 06) //Voice Will Only Activate between 6PM & 6AM
                 StartCoroutine(BrightnessResponse());
                 
 
             else if (slider.value < 0.10f && oldValue >= 0.10f) //----------this has changed
                 //source.PlayOneShot (DarknessAudioClips [Random.Range (0, DarknessAudioClips.Length)]);
                 StartCoroutine(DarknessResponse());
             break;
Comment
Add comment
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

1 Reply

  • Sort: 
avatar image
1
Best Answer

Answer by allenallenallen · Jan 09, 2016 at 04:04 PM

Well, looking at your first line of code. You can't have a military time that's greater than 15 and less than 6 at the same time.

 slider condition stuff && (sysHour >= 15 && sysHour <= 06)   // An integer can never fit both requirements at the same time.

Given that you're using the DateTime.Hour property: https://msdn.microsoft.com/en-us/library/system.datetime.hour(v=vs.110).aspx

Perhaps you meant this?

 slider condition stuff && (sysHour >= 18 || sysHour <= 6) // Where it's truly between 6 PM and 6 AM

Since the value is supposed to be in military time, from 0 to 23.

00:00 would be 12:00 AM

15:00 would be 3:00 PM (You made the mistake of using 15 in your code.)

18:00 would be 6:00 PM

23:00 would be 11:00 PM

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 09, 2016 at 05:20 PM 0
Share

@allenallenallen, Thanks man, I changed it to this and now it should only provoke a brightness detected response if the LDR senses those values and the actual system time is between 6P$$anonymous$$ & 6Am if I understand that right?

Now should I be casting my values for the time exactly like you have them at 00:00 for midnight and 15:00 for 3P$$anonymous$$ and so on or is the way I have it here valid too?

 // else check if we need to play a sound and do it
             if //(slider.value > 0.9f && oldValue <= 0.9f) //This will call the voice no matter what time of day or night it is
                 (slider.value > 0.9f && oldValue <= 0.9f && (sysHour >= 18 || sysHour <= 06)) //Voice Will Only Activate between 6P$$anonymous$$ & 6A$$anonymous$$
                 StartCoroutine(BrightnessResponse());
 
             else if (slider.value < 0.10f && oldValue >= 0.10f) //At These Values activate a "Darkness Detected" response
                 StartCoroutine(DarknessResponse());
             break;
avatar image allenallenallen KnightRiderGuy · Jan 09, 2016 at 05:24 PM 1
Share

The way you do it is fine. I just say the :00 to explain the time thing. They should all be integers.

There is one thing though. I think it's better to write 6 ins$$anonymous$$d of 06. I'm not sure if 06 would give an error but it's best to keep integers simple.

avatar image KnightRiderGuy allenallenallen · Jan 09, 2016 at 05:35 PM 0
Share

@allenallenallen, Thanks man some points co$$anonymous$$g your way :) Now I can't wait till 6P$$anonymous$$ just to see if it works lol. Like I couldn't just tweak a temporary value ;) I did already and he seems to work. Now $$anonymous$$ITT will only say he detects light if it is between 6 P$$anonymous$$ and 6 Am :)

Follow this Question

Answers Answers and Comments

51 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

Related Questions

Get Temperature Value and Prompt an Action 0 Answers

Can Someone Explain Why Message does not show Anything In Inspector 0 Answers

Can't Locate gameobject in array 3 Answers

problem with lists 0 Answers

Infinite Time inbetween if statements? 2 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