I need to replace the default Input.GetAxis(“Horizontal”) and Input.GetAxis(“Vertical”) with custom ones within a script.But I’m a little unsure of how. Input.GetAxis is a float but I wasn’t able to find any details of what values are stored in it mentioned by the API. Is it just the keycodes when pressed added together like the code below or does Input.GetAxis store more than just the keycode values?
using UnityEngine;
using System.Collections;
public class ExampleClass : MonoBehaviour {
Public float w;
Public float s;
Public float wPlusS;
void Update() {
if (Input.GetKeyDown("w")){
++w;
}
if (Input.GetKeyDown("s")){
--s;
}
wPlusS = w + s;
}
}
Input.GetAxis() returns a float from -1 to +1 depending on how far along the local axis the object is (think like a controller thumbstick). For keyboard controls, it’s always -1 and +1 exactly.
I’m a little confused on what you’re asking. If you need to define your own buttons or states, check Edit → Project Settings → Input.
If that doesn’t help, please try to clarify exactly what you’re asking.
I want to be able to add customizable controls to my game. I can’t do that with the inputs in the input manager because they can’t be changed during runtime. That’s why I want to create my own custom axis.
So it acts more like a switch rather an increase/decrease and it takes into account the gameobject’s localposition as well? Like input.getaxis = Input.GetKeyDown(“w”) || Input.GetKeyDown(“s”) + gameobject.transform.position; ? Sorry if the pseudo code is bad I’m having a hard time understanding this.