player move unity
A downloadable game for Windows, macOS, Linux, and Android
player script
public float runspead=10;
public float nespead=-5;
public float spead=5;
public Animator playerAN;
private void Awake()
{
playerAN = GetComponent<Animator>();
}
void Update()
{
if (Input.GetKey(KeyCode.LeftShift))
{
playerAN.SetBool("isbackr", false);
transform.position = transform.position + transform.forward * runspead * Time.deltaTime;
playerAN.SetBool("iswalk", false);
playerAN.SetBool("run",true);
}
if (Input.GetKeyUp(KeyCode.LeftShift))
{
playerAN.SetBool("isbackr", false);
playerAN.SetBool("iswalk", false);
playerAN.SetBool("run", false);
}
if (Input.GetKey(KeyCode.W))
{
playerAN.SetBool("run", false);
playerAN.SetBool("isbackr", false);
transform.position = transform.position + transform.forward * spead * Time.deltaTime;
playerAN.SetBool("iswalk",true);
}
if (Input.GetKeyUp(KeyCode.W))
{
playerAN.SetBool("run", false);
playerAN.SetBool("isbackr", false);
playerAN.SetBool("iswalk", false);
}
if (Input.GetKey(KeyCode.S))
{
transform.position = transform.position + transform.forward * nespead * Time.deltaTime;
playerAN.SetBool("isbackr",true);
playerAN.SetBool("run", false);
playerAN.SetBool("iswalk",false);
}
if (Input.GetKeyUp(KeyCode.S))
{
playerAN.SetBool("isbackr", false);
playerAN.SetBool("run", false);
playerAN.SetBool("iswalk", false);
}
}
camera move
float mouseX;
float mouseY;
SceneManager levels;
public float sensitivity = 100f;
public Transform player;
float rotation = 0f;
public float minAngle = -90f;
public float maxAngle = 90f;
// Start is called before the first frame update
void Start()
{
Cursor.visible = false;
}
// Update is called once per frame
void Update()
{
mouseX = Input.GetAxis("Mouse X") * sensitivity;
mouseY = Input.GetAxis("Mouse Y") * sensitivity;
rotation -= mouseY;
rotation = Mathf.Clamp(rotation, minAngle, maxAngle);
transform.localRotation = Quaternion.Euler(rotation, 0, 0);
player.Rotate(Vector3.up * mouseX);
if (Input.GetKey(KeyCode.E))
{
Cursor.visible = true;
}
if (Input.GetKey(KeyCode.Q))
{
Cursor.visible = false;
}
}