Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 14 Next capture
2021 2022 2023
2 captures
12 Jun 22 - 14 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 /
  • Help Room /
avatar image
0
Question by PunchGoat · Oct 15, 2016 at 06:07 AM · javascriptuser interfacegetbuttondown

I can't get Input.GetButtonDown to return true when the specified button is pressed.

I'm creating a simple inventory for my game. I created two canvases. One to display the main inventory and a second smaller one to display current equipped items. When the main inventory is displayed I don't want the smaller canvas to show and vice versa, All I want this code to do is enable and disable the canvases when I press I, but so far nothing is happening. The canvases do nothing, and the debug log doesn't display in the console. Here's the code that's not working:

  var inventoryKey = Input.GetButtonDown ("Inventory");
     
     if (inventoryKey == true) {
 
         Debug.Log("Inventory button working");
     
         if (inventoryVisible == true) {
 
             inventoryCanvas.enabled = false;
             equippedCanvas.enabled = true;
             inventoryVisible = false;
         }
         
         if (inventoryVisible == false) {
 
             inventoryCanvas.enabled = true;
             equippedCanvas.enabled = false;
             inventoryVisible = true;
         }

I've got the command in an update function. I've tried using GetKeyDown with key codes, but that doesn't work either. I've checked the "Inventory" key in the inspector and everything is as it should be. I've tried assigning different keys to it, "Fire 1" and "Submit", but that hasn't helped either. I'm not sure where I'm going wrong with this and any help would be greatly appreciated.

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 Bmarlyman21 · Oct 15, 2016 at 08:06 PM 0
Share

You've created a loop with your "inventoryVisible" variable. Remove the third line from both of your if statements where it sets inventoryVisible as true or false. Then have the sole function of your "inventory" button be to switch "inventoryVisible" on and off.

avatar image PunchGoat Bmarlyman21 · Oct 19, 2016 at 05:23 PM 0
Share

Thanks, I did what you said and it's working perfectly.

avatar image Bmarlyman21 PunchGoat · Oct 19, 2016 at 08:04 PM 0
Share

Glad to help.

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

102 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 avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

Carrying physical game objects in javascript scripting problems with Unity 5. 2 Answers

I keep getting the error "NullReferenceException: Object reference not set to an instance of an object RobotFollow.Update () (at Assets/Scripts/RobotFollow.js:23)" 1 Answer

Variables not showing up in Inspector (JavaScript) 2 Answers

yield WaitForseconds not working? 1 Answer

GetComponent is not a member of Object 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