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 kkzz19 · Jan 31, 2013 at 12:59 AM · changecontrolskeysin-game

Changing controls in game, after application has launched

Hi, I want to know if it is possible to change control inputs in-game (after the application has launched). For example, I could have a "Change Controls" menu in the main menu, where the user can click on a box, for example "Move forward", press what button they want to move forward, and have that button be saved as the move forward key.

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

2 Replies

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

Answer by robertbu · Jan 31, 2013 at 01:51 AM

One solutions is to put your keycode checks into variables. Something like (in C#):

 KeyCode kcForward = KeyCode.UpArrow;
         
 if (Input.GetKeyDown (kcForward)) { // Do the forward stuff }

Later you can reassign the value.

 kcFordward = KeyCode.W;

So now the 'W' key will move forward. Of course you'll have to write the interface that allows the user to change the keys mappings for your game.

Comment
Add comment · Show 4 · 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 kkzz19 · Jan 31, 2013 at 05:25 AM 2
Share

I was wondering if there was an easier way to have the user change the key mappings than hard coding an if statement for every single key on the keyboard.

For example, ins$$anonymous$$d of doing

 if(Input.Get$$anonymous$$eyDown($$anonymous$$eyCode.W)) 
     kcForward = $$anonymous$$eyCode.W

for every single $$anonymous$$eyCode there is, is there a function that returns the key that the user pressed as a $$anonymous$$eyCode variable?

If not, I guess I'll have to write the interface myself.

avatar image robertbu · Jan 31, 2013 at 05:41 AM 0
Share

You can see all the keys pressed. Here is an example from the script reference:

 // Detects keys pressed and prints their keycode
 function OnGUI() {
     var e : Event = Event.current;
     if (e.is$$anonymous$$ey) {
         Debug.Log("Detected key code: " + e.keyCode);
     }
 }


avatar image robertbu · Jan 31, 2013 at 06:09 AM 0
Share

Or you could create an array (or a class) that remaps as needed:

 if (Input.Get$$anonymous$$eyDown (Remap[$$anonymous$$eyCode.UpArrow])) { // Do the forward stuff }
avatar image kkzz19 · Feb 01, 2013 at 09:54 PM 0
Share

That worked. Thanks.

avatar image
-1

Answer by dehow64 · Nov 06, 2013 at 01:43 AM

I tried using the solution provided and I still can't get my player to move. Here's what I put

 enter code here
 using UnityEngine;
 using System.Collections;
 
 public class Change_Controls : MonoBehaviour {
 
     public string moveForward = "x";
     // Use this for initialization
     void Start () {
     
     }
     
     // Update is called once per frame
     void Update () {
     
             KeyCode kcForward = KeyCode.X;
      
     if (Input.GetKeyDown (kcForward)) { // Do the forward stuff }
         
             kcForward = KeyCode.X;
             
     }
 }
 }
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 Scruubbi · Nov 12, 2013 at 06:45 PM 0
Share

You should use Input.Get$$anonymous$$ey ins$$anonymous$$d of Input.Get$$anonymous$$eyDown.

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

11 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

Related Questions

Change the keycode in game by associating it to the previous script 0 Answers

How to change my game into an ios game 1 Answer

setting up key binding options 1 Answer

How do I make a transforming jet control system? 1 Answer

Changing controls from keyboard to touch in the game 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