Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 13 Next capture
2021 2022 2023
1 capture
13 Jun 22 - 13 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 /
avatar image
0
Question by HelloFinland · Dec 27, 2014 at 08:07 PM · inputbooleanbool

Boolean and input relation

Hello, i have script which checks the bool. But what i want is; i want to make boolean valid for some seconds so that i can press the keycode within that seconds of boolean valid and it will be verified by boolean and says , "you have enter correct keycode"

so i am looking for some seconds boolean valid after it gets true. If anyone has idea, please tell me.

Comment
Add comment · Show 3
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 Graham-Dunnett ♦♦ · Dec 27, 2014 at 08:07 PM 0
Share

Post the code you have written, and explain what doesn't work correctly.

avatar image richyrich · Dec 27, 2014 at 09:38 PM 0
Share

Sounds like you need a timer... When you check for user input, you check first whether the time has elapsed, if not, then check to see if user has pressed enough keys for the password.

You could extend code from this tutorial:

https://www.youtube.com/watch?v=aHf96fBBY$$anonymous$$0

Have a go first, but if you're stuck for a few hours and you've checked online for other info, update your post with your new script and tell us where the problem is :)

avatar image HelloFinland · Dec 28, 2014 at 04:53 PM 0
Share

okay, here is my code using UnityEngine; using System.Collections; using System.IO;

 public class RandomLight : $$anonymous$$onoBehaviour {
 
     public bool checkLights = true;
     
     private const string FileName = "LeftLight.txt";
 
 
     IEnumerator Start ()
     {
         checkLights = false;
         while (true)
         {
             light.enabled =true; //toggle on/off the enabled property
             yield return new WaitForSeconds(2);
             checkLights = false;
 
             light.enabled = false;
           yield return new WaitForSeconds(Random.Range(3, 8));
 
             checkLights = true;
 
 
                
                 if(checkLights)
                 {
                 if(!Input.Get$$anonymous$$ey($$anonymous$$eyCode.B))
                    {
                     
 
                 if(File.Exists(FileName))
                 {
                     Debug.Log("File already exists");
                     
                     
                 }
                 
                 StreamWriter sr = File.AppendText(FileName);
                 
                 sr.WriteLine ( " You didnt press the right button  " +  System.DateTime.Now.ToString("yyyy.$$anonymous$$$$anonymous$$.dd hh:mm:ss"));
                 
                 sr.Close();
 
                 }
             
                 }
                 }
     }
 }

 

so basically what this code does is, it checks the random light value and when it the bool finds the light enabled, i have to press the keycode immedately to get the response from the bool and it should valid that one. it works perfectly now and keycode also reponse if i press very fast but its very hard to press the keycode immedately. so, i want to make bool valid for some period of seconds so that the keycode which i press will be valid by bool.

0 Replies

· Add your reply
  • Sort: 

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

4 People are following this question.

avatar image avatar image avatar image avatar image

Related Questions

C# Parameter questions 2D game 1 Answer

How to schedule responses (based on player's input text) for text adventure game? 0 Answers

GetComponent, set boolean to true but it willn't revert 3 Answers

How to change the bool values in the rocket? Getting game objects to communicate 3 Answers

Can an Input event be 'faked' with a script? 1 Answer


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