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 /
avatar image
0
Question by Breck1 · Apr 16, 2018 at 08:22 AM · buttonwaitforsecondskeyboard

How do I make a program that first press button 1 release it and then press button 2 in order to walk?

I want to make the player walk by first pressing one button, let's say "A" then releasing that button and after that pressing another let's say "D". so press "A" release "A" press "D", is one step. Then releasing "D" and pressing "A" would be a second step. This continues until the player stops the sequence.

If the player wait too long the chain should stop. that is just because the player presses "D" and the last button pressed was "A" shouldn't make the character walk.

Comment
Add comment · Show 2
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 shadowpuppet · Apr 16, 2018 at 04:28 PM 0
Share

So am I understanding this correctly. "A" release, then "D" is - say left foot moving forward, release "D" then press "A" would then move the right foot forward? Seems like a tiring way for the player to make his character walk. but...not my place to comment on gameplay. Tried this out and it seems to work although the Debug prints out "left" or "right" twice for each step. Not sure about the the player waiting to long. A timer or coroutine of some sort. here is a little something .far from perfect but it's a start

   public bool leftFoot;
 public bool rightFoot;
 public float walkTimer = 1.5f;
 public bool tooLong;
 public bool walking;
 void Start(){
     leftFoot = false;
     rightFoot = false;
 }
 void Update(){
     if(walking == true)
     walkTimer -= Time.deltaTime;
     if (leftFoot == true || rightFoot == true) 
         walking = true;
     if (walkTimer <= 0  ) {
         tooLong = true;
         leftFoot = false;
         rightFoot = false;
         walking = false;
         walkTimer = 0;
         StartCoroutine(walkRestart());
     }
     if (Input.Get$$anonymous$$eyUp($$anonymous$$eyCode.A)&&  tooLong == false){
         leftFoot = true;
         rightFoot = false;

     } 
     if (Input.Get$$anonymous$$eyUp($$anonymous$$eyCode.D)&&  tooLong == false){
         leftFoot = false;
         rightFoot = true;
     } 
     if (Input.Get$$anonymous$$eyDown($$anonymous$$eyCode.D) && leftFoot == true &&  tooLong ==false){
         Debug.Log ("left");
         walkTimer  = 1.5f;
         //code for left foot forward
     }
     if (Input.Get$$anonymous$$eyDown($$anonymous$$eyCode.A) && rightFoot == true &&  tooLong ==false){
         Debug.Log ("right");
         walkTimer  = 1.5f;
         //code for rightfoot forward
     }
 }
 private IEnumerator walkRestart(){
     yield return new WaitForSeconds(1);
     
     walkTimer = 1.5f;
     tooLong = false;
 }

}

avatar image Breck1 shadowpuppet · Apr 17, 2018 at 08:02 AM 0
Share

Thank you!

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

91 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 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 to Play Sound on Button Highlight 2 Answers

I have a button with a cooldown. How do I make it so the cooldown time increases with each press of the button? 2 Answers

wait for 3 seconds button?? 3 Answers

Numpad Keypress not being registered on mobile phone. 0 Answers

Putting a delay in a button OnClick ? (Javascript) 3 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