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.
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.
Thanks, I did what you said and it's working perfectly.
Your answer
![](https://koobas.hobune.stream/wayback/20220612094644im_/https://answers.unity.com/themes/thub/images/avi.jpg)
Follow this Question
Related Questions
Carrying physical game objects in javascript scripting problems with Unity 5. 2 Answers
How to play an audiosource and have a canvas message still show? 0 Answers
How to load level after typing somthing? 1 Answer
Please help me with my mouse pointer 0 Answers
addComponent c# script by java 0 Answers