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 Hamesh81 · Nov 01, 2012 at 04:55 AM · booleanboolordersequence

How can I trigger booleans in a specific order?

I have 3 booleans which are each triggered by a different key press setup via the Input settings.

  • When the W or Up Arrow key is pressed, tapW = true

  • When the A of Left Arrow key is pressed, tapA = true

  • If both tapW & tapA are true the third bool, tapAW = true

This is good and all but I would like the tapAW bool to become true only if the A key is pressed first followed by the W key (hence the bool name "tapAW"). At the moment tapAW returns true whether the combination W then A is pressed, or A then W is pressed, and I would like to trigger tapAW only when A is first followed by W. I've attached the relevant snippet of my simple script below. How could I do this?

 public bool tapW = false;
 public bool tapA = false;
 public bool tapAW = false;
 public bool tapWA = false;
 
 //In the Update function
 
    if (Input.GetButtonDown ("Walk") && !tapW) {
                  tapW = true;
             }
    if (Input.GetButtonDown ("WalkLeft") && !tapA) {
                  tapA = true;
             }
    if (tapA && tapW) {
                   tapA = false;
                   tapW = false;
                   tapAW = true;
             }
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

2 Replies

· Add your reply
  • Sort: 
avatar image
1

Answer by suresh.murugesan · Nov 01, 2012 at 05:48 AM

you check the time difference of first and second button pressed then you can solve this problem . . .

Comment
Add comment · Show 1 · 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 Hamesh81 · Nov 01, 2012 at 08:10 AM 0
Share

Yes that makes sense. I am using a timer for the double tap functionality, but that is a different implementation all together. Could you provide an example of what you mean?

avatar image
1

Answer by swatmaster69 · Nov 01, 2012 at 05:48 AM

You could put the buttons in an array, then search it. Of course, that would get ugly fast if you plan to use more than two keys. Something like this:

 ArrayList taps = new ArrayList();
 
 void Update()
 {
   tapW = tapA = tapWA = tapAW = false;
 
   if (Input.GetButtonDown("W"))
     taps.Add('W');
   else if (Input.GetButtonDown("A"))
     taps.Add('A');
 
   if (taps.Count == 1)
   {
     if (taps[0] == 'W')
       tapW = true;
     else
       tapA = true;
   }
   else if (taps.Count == 2)
   {
     if (taps[0] == 'W' && taps[1] == 'A')
       tapWA = true;
     else
       tapAW = true;
   }
   else if (taps.Count == 3)
     taps.Clear();
 }
Comment
Add comment · Show 2 · 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 Hamesh81 · Nov 01, 2012 at 08:06 AM 0
Share

Yes I am planning to use more than two keys down the track. Thanks for the suggestion anyway ;)

avatar image swatmaster69 · Nov 11, 2012 at 03:31 AM 0
Share

So are you trying to decide whether the player entered a valid combo or something? If so, you could make a list of $$anonymous$$eyCodes and run one or more for loops comparing that list to lists of valid combos.

If not, what are you trying to do? Some more details might be helpful.

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

12 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

Related Questions

Accessing non-static bools across scripts 2 Answers

Change Bool When Audio Clip Ends C# 1 Answer

Play Audio Once if Bool==True 2 Answers

Could use some help on making my runaway/chase/follow/patrol script cooperate with each other 1 Answer

Mouse click IF not checking properly 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