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 ItsK4rma · Jan 27, 2013 at 10:43 PM · menujoystickxbox360

Navigating menus using Joystick

I have a menu system in my game. The menu works with arrow keys on the keyboard and with the joystick/d-pad on an xbox controller. Since the joystick uses an axis I can not use Input.GetButtonDown, I have to use Input.GetAxis("Vertical"). I have Vertical mapped to the xbox joystick, the d-pad, and the arrow keys to cover both in 1 command.

The problem I was having then, was when I would hold down the joystick it would rapidly move ( I mean 10/second ) since this is in the Update() function.

As an attempt to solve the problem I have added a boolean value. When 0 < input > 0 it calls the MoveUp or MoveDown function appropriately. Within those two functions I have a value that turns false, and in MoveUp/Down function if this value is false it does not continue.

(I also have a counter which is an int. It only goes from 1 to 3 each representing an item in the menu, I only have 3 at this time.

Please I am open to any improvements to this code.)

 function Update(){
     var inputY = Input.GetAxis("Vertical");
 
     if (inputY > 0){
         MoveUp();
     } else{
         canMoveUp = true;
     }
     
     if (inputY < 0){
         MoveDown();
     } else{
         canMoveDown = true;
     }
 }
 
 function MoveUp(){
     if (canMoveUp == true){
         if (count == 3){
             count = 2;
             canMoveUp = false;
         } else if (count == 2){
             count = 1;
             canMoveUp = false;
         }
         
         if (count == 1){
             count = 1;
             canMoveUp = false;
         }
     }
 }
 
 function MoveDown(){
     if (canMoveDown == true){
         if (count == 1){
             count = 2;
             canMoveDown = false;
         } else if (count == 2){
             count = 3;
             canMoveDown = false;
         }
         
         if (count == 3){
             count = 3;
             canMoveDown = false;
         }
     }
 }

Now, I have a problem with this code. If I am holding down the down key (or holding the joystick down), I'm essentially calling this MoveDown function every frame. I believe this causes some lag on the system because if I let go and try to move down again rapidly, there is some delay (1-2secs). It is a minor bug, but since my menu systems are working 100% at this point. I'd like to refine and fix this bug.

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

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

9 People are following this question.

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

Related Questions

How do you make a Main Menu that only takes Joystick input and is not affected by the Cursor 2 Answers

How do I 360 A button working 0 Answers

How can i move an object in screen space with xbox joystick 1 Answer

How to use the XBox 360 Controller D-Pad (PC) ? 6 Answers

Tattie Bogle doesn't distinguish between multiple Xbox 360 controllers for Mac OS X El Capitan 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