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 DevonJS · Mar 13, 2011 at 05:53 PM · inputbuttonrecording

Button remapping.

The script i made doesn't record what the person presses after pressing the key. Thats all I really know. but you guys can look at it to see if theres any other things i could do..</p> <pre><code> var inputkey1 = "w"; var inputswitch = false; var inputkey1valid = true; var inputkeychanged = false; var inputkey1a = "w"; var inputkey1b = "a"; var inputmessage1 = "1111111113022"; var inputkey2 = "2"; var inputmessage2 = "222223022"; var inputkey1false = false; private var gt: GUIText; function Start () { gt = GetComponent(GUIText); if( gt == null ) Debug.Log("No GUIText component found"); } function Update () { //to allow changing of keys ((press before remapping is taking place)) if(Input.GetKeyDown("")) { inputswitch = true; inputkey1valid = false; inputkey1false = true; }

      //if you pressed the key of the choice to change and you pressed ` before change the inputkey to the recorded key
      //and reset inputswitching to false so it works and stays that variable.
        if(Input.GetKeyDown(inputkey1) &amp;&amp; inputswitch &amp;&amp; inputkey1false)
       {
        var inputkey1b = Input.GetKeyDown;
        inputswitch = false;
        inputkeychanged = true;
        inputkey1valid = true;
        inputkey1false = false;
       }

 if(inputkey1false)
 {
  inputkey1valid = false;
 }



          //if the keys are opted to change then its the changed/recorded key      
           if(inputkeychanged)
         {
         inputkey1 == inputkey1b;
         inputkey1valid = true;
          }
         //reset the keys  if = is pressed.
          if(Input.GetKeyDown("="))
          {
             inputswitch = false;
             inputkeychanged = false;
             inputkey1 == inputkey1a;
             inputkey1valid = true;
          }

         if(Input.GetKeyDown(inputkey1) &amp;&amp; inputkey1valid)
         {
            gt.text = inputmessage1;
         }
     if(Input.GetKeyDown(inputkey2))
         {
            gt.text = inputmessage2;
         }


}

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 Myth · Mar 13, 2011 at 09:10 PM 1
Share

if it isn't absolutely necessery I wouldn't use an ingame console to change keys, I would use the input manager under project in the edit menu.

1 Reply

· Add your reply
  • Sort: 
avatar image
0

Answer by AngryOldMan · Mar 14, 2011 at 03:04 AM

I don't know how but this script doesn't show any compiler errors. It still doesn't seem to do anything though. Like Myth says is there any specific need to remap the keys at runtime? If you just want to change the keys you can go into "edit ~> project settings ~> input" and specify the keys and their names (which is the method used for calling them) In there you can set an axis' positive and negative buttons (or just a buttons positive if its only an on/off button) you can also set alternative buttons (so effectively setting two sets of keys for the same input) if for instance with movement you prefere to use WASD and a friend preferes the directional keys it is handy to set alternative keys.

If however you want to press a button during the game and completely change a control set may I suggest still changing the inputs via project settings but setting two completely different sets of keys, then creating a script which on a certain key press, disables one set of controls and enables the other. Which can be done all in the same script with a simple if variable, for instance

var ControlSet1 = true;

function Update () { if (Input.GetButtonDown ("ControlChange")) { ControlSet1 = false; } if (ControlSet1 == true) { //define the default controls for example moveDirection = Vector3(Input.GetAxis("Horizontal"),Input.GetAxis("Vertical"),0); moveDirection = transform.TransformDirection(moveDirection);
} if (ControlSet1 == false) { //define controls that you have switched to for example moveDirection = Vector3(Input.GetAxis("CSTHorizontal"),Input.GetAxis("CSTVertical"),0); moveDirection = transform.TransformDirection(moveDirection);
} }

CTS stands for Control Set Two but this is just an example you would have define the exact naming convention in the input settings then adapt your script to suit.

Comment
Add comment · 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

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

No one has followed this question yet.

Related Questions

How to use Button as Cross Platform Input 0 Answers

how to create buttons using iphone look and feel?? 2 Answers

Ensuring that a button is released before checking that it's pressed? 2 Answers

Steelseries 3gc controller key mappings 0 Answers

Why right alt (alt gr) acts like left ctrl?! 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