- Home /
how to move player with getAxis and UI buttons
pretty self-explanatory title but let's expand a little so I now have a few UI buttons left and right but my players left and right movement is controlled through Input.GetAxis("Horizontal") so I'm wondering if I can split this somehow into left and right this is the block so I need to check if move horizontal is 0 and then move left or right but I don't know how you can move left or right using getaxis or if I can swap it to something like getKey and still keep the same speed and such, here's how I'm passing the code to my UI button, someone from here helped me with this,
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.SceneManagement;
using UnityStandardAssets.CrossPlatformInput;
public class Player : MonoBehaviour
{
public float moveSpeed = 600f;
float movement = 0f;
void Update()
{
movement = Input.GetAxisRaw("Horizontal");
}
private void FixedUpdate()
{
transform.RotateAround(Vector3.zero, Vector3.forward, movement * Time.fixedDeltaTime * -moveSpeed);
}
Your answer
Follow this Question
Related Questions
The name 'Joystick' does not denote a valid type ('not found') 2 Answers
Keeping forward transform 2 Answers
Third Person Controller Design 1 Answer
Problem with a custom input handler 1 Answer