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
1
Question by NutellaDaddy · Jun 10, 2014 at 03:48 AM · c#variablekeycode

Why does this not work? Trying to use Keycode in variable.

This script isn't working because it says that the Input.GetButtonDown doesn't take a string ,but I'm inserting a Keycode variable. Here's the script:

 //SAMPLE OF THE CODE
     public KeyCode onOffButton = KeyCode.Tab;
 
     private bool inventoryOn;
 
 
 void InventoryOnAndOff()
     {
         if (Input.GetButtonDown (onOffButton)) 
         {
             inventoryOn = !inventoryOn;
         }
     }
Comment
Add comment · Show 1
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 Bunny83 · Jun 10, 2014 at 06:08 AM 0
Share

:) Next time read the error more carefully. Input.GetButtonDown only takes a string, so you read the error the other way round.

1 Reply

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

Answer by oasisunknown · Jun 10, 2014 at 05:36 AM

I did some testing on this and here is what I came up with.

1) set up your keykode in the input manager under Edit>project settings>Input

in the input manager you can name the input and set the keycode to what ever you like for example some of the other ones are "Fire1" ect. (for my testing purposes I named it "Inventory")

setting it up through the input manager allows you to change it easily and also let your player map any key to it that they like. (provided you give them access to it.)

2) how you would change it in your script after setting up the input manager would be as follows.

 if (Input.GetButtonDown ("Inventory"))// this calls the input named inventory from the input manager

3) the last thing that you have to do is call your function from the Update method.

because right now you dont have one so your function wont do anything until called anyways.

ie.

 void Update ()
 {
   InventoryOnAndOff();
 }

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 NutellaDaddy · Jun 10, 2014 at 04:51 PM 0
Share

Yes, I know. I was only giving a sample of the script that I had. Thanks for the answer!

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

23 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

Related Questions

The name 'Joystick' does not denote a valid type ('not found') 2 Answers

Assigning varaibles to prefabs 1 Answer

Declaring Variable in Child & Access as Parent 2 Answers

Starting out C# help 2 Answers

Change variable value of a script from another script. both in different Game object 1 Answer


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