# How to assign separate controller axes to Player1, Player2?

I need to have two players moving in a level for a school project and my player controller is already set up for using axis inputs (as opposed to discreet buttons) for directional input. I already know I can assign custom key inputs from the inspector if I just declare a public variable (initialization optional because there is a drop-down list in the inspector):

public KeyCode jumpInput = KeyCode.Space;


How can I assign custom directional axis inputs from the inspector? I already have alternative horizontal and vertical axes defined in my preferences, I just need to know how to assign them.

Been putting this project together for 36 CONTIGUOUS hours and I am ready to put it (and myself) to bed. Thank you in advance for your time.

EDIT: My confusion was coming from (beyond being awake too long) thinking that I needed a special data type (like KeyCode) for an Axis, and couldn't find it in the reference. But I didn't consider making a public string and plugging that into the input. This way, I just need to know what I named the new axes and use that for the public string.

• Presumably you tried exposing your axis name as a public string variable, similar to your strategy for configuring keys? Where specifically did you run into trouble? – DMGregory Jul 20 '19 at 14:20
• I want to use the same controller script for both players so I wanted a drop-down list from the inspector so I could just have every "GetAxis()" invocation reference whatever axis the GameObject (player) is assigned (or similar). I don't want to write new methods or new scripts for each player. It's easy to change the label for a button or axis, but not refactoring the entire script – hatinacat2000 Jul 20 '19 at 15:00
• You would not need to write any new methods. This is only a public variable, the same technique you're using for your keys, except the value is a string instead of an enum. – DMGregory Jul 20 '19 at 15:16
• You are absolutely correct in your assumption, I just can't find documentation on how to do it for an axis like I was able to do it for a key. Keys have single keycodes; axes have the name I set in the project settings but also have negative and positive keycodes. Some people online said it can't be done but that was a few years ago. I'm looking for a way to assign the axes in the inspector that I made in my preferences (which basically amounts to removing the alternative axis keys up/down/, left/right and putting them in their own axes). – hatinacat2000 Jul 20 '19 at 19:37
• I'm not following. If you have an axis defined that's called "Player1Horizontal" then what's to stop you from making a variable like public string horizontalAxisName = "Player1Horizontal"; then using GetAxis(horizontalAxisName) to read it? For player 2, you'd just change the string in the inspector to read "Player2Horizontal" instead, a pure data change with no code changes required. What specific behaviour are you unable to achieve in this way? – DMGregory Jul 20 '19 at 20:29

float newHorizontal = Input.GetAxis ("YourNewHorizontalInputName");