Hi all
I have a simple character controller that moves my character in 4 directions using input.GetAxis just fine but I am having a really difficult time figuring out how to access it for use in say an if statement.
I know that using GetKey I could use something like the following and then easily add more logic into it, and set up specific logic for left right up and down.
void Update () {
if (Input.GetKey(KeyCode.RightArrow)){
transform.position += Vector3.right * speed;}
How would I do this using GetAxis?
By the way I decided on a controller that uses input.GetAxis so that I could use a rigidbody to be able to use the physics engine later on in case anyone was wondering.
Here is my relevant code, Thank you so much in advance!
public Vector2 speed = new Vector2 (50, 50);
private Vector2 movement;
private Rigidbody2D playerRigid;
void Start ()
{
playerRigid = GetComponent<Rigidbody2D> ();
}
void Update ()
{
float inputX = Input.GetAxis ("Horizontal");
float inputY = Input.GetAxis ("Vertical");
movement = new Vector2 (
speed.x * inputX,
speed.y * inputY);
}
void FixedUpdate ()
{
playerRigid.velocity = movement;
}