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 Conect11 · Sep 25, 2013 at 02:42 AM · buttongamepadsensitivity

Button press wipes out my inventory

Since a search, and fiddling didn't fix the problem, I figured I'd ask the folks who know what they're doing. (and I thank God that you do!) Using a gamepad, I go into my inventory. Let's say I want to eat a piece of toast, and I have four pieces in said inventory. I have the "eat toast" command assigned to button 2. If I press button 2, however, I'll instantly eat all four pieces of toast. Have tried changing input sensitivity, gravity, dead space, though I figured only sensitivity would be relevant. Nothing ever changed though, and I'm hoping someone might know what I'm doing wrong. If it helps, I'm using a Logitech Gamepad F310 controller. Thanks, and God bless.

EDIT: Code below. BTW: Yes, I realize it's a mashup. Am in the middle of changing it from array based to static var based to make it more (newb) friendly with PlayerPrefs.

 static var inventoryArray : int[] = [0,0,0,0,0,0,0,0,0,0,0,0,0,0,0];
 var inventoryText : GameObject;
 static var HardTack : int = 1;
 
 
 
 function Update () {
 
 inventoryText.guiText.text = "Health Potion " + "[" + inventoryArray[0] + "]" + "\n" + "Hard Tack " + "[" + HardTack + "]" + "\n" + "Water " + "[" + inventoryArray[2] + "]" + "\n" + "Apple Brew " + "[" + inventoryArray[3] + "]" + "\n";
 
 if(Input.GetButton("Stuff"))
 
 if(inventoryArray[0] > 0) {
 
 healthPotion();
 }
 if(Input.GetButton("Sword Slash"))//Right HERE
 
 if(HardTack > 0) {
 
 hardTack();
 }
 }
 //inventoryArray[0]++;
 //inventoryArray[1] ++;
 
 function healthPotion ()  {
 
 Playerhealth.curHealth += 15;
 inventoryArray[0] -=1;
 }
 
 function hardTack ()  { //RIGHT HERE
 
 Playerhunger.curHunger -= 5;
 HardTack -=.5;
 }
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

· Add your reply
  • Sort: 
avatar image
1
Best Answer

Answer by fafase · Oct 11, 2013 at 06:43 PM

Since you have no code shown on your question, I go with a guess:

you have

 if(Input.GetKey(KeyCode.JoystickButton2)){ // eat only one of those toasts}

That should eat only one but since the method returns true each frame and a frame is way too fast for you to press only once, then it returns for as long as you pressed and your 4 toasts are gone in 4 frames, a few ms.

Try with :

  if(Input.GetKeyDown(KeyCode.JoystickButton2)){ // eat only one of those toasts}

If it is not the case then you need to post your code(which you should have done in the first place).

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 Conect11 · Oct 11, 2013 at 06:50 PM 0
Share

thanks fafase. I figured that this was an settings - input issue, hence no code. Totally and honestly sorry, didn't want to not give folks the tools to help. Will edit to include code.

EDIT: fafase, you're a genius. That did the trick.

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

15 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

Related Questions

gamepad input sensitivity 0 Answers

Gamepad press and release in Input Action - UI Buttons 1 Answer

Temporarily disable gamepad button 1 Answer

Joystick gamepad input overly sensitive 1 Answer

Find out if any Button on any Gamepad has been pressed and which one 6 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