57 lines
1.5 KiB
C#
57 lines
1.5 KiB
C#
using System.Collections;
|
|
using System.Collections.Generic;
|
|
using UnityEngine;
|
|
|
|
public class Player_Manager : MonoBehaviour
|
|
{
|
|
|
|
public float speed = 10;
|
|
public float runSpeed = 15;
|
|
public float rotateSpeed = 5;
|
|
public float mouseSensitive = 200;
|
|
private bool run = false;
|
|
private Camera playerCamera;
|
|
private Rigidbody rigidBody;
|
|
|
|
|
|
// Start is called before the first frame update
|
|
void Start()
|
|
{
|
|
playerCamera = GetComponentInChildren<Camera>();
|
|
rigidBody = GetComponent<Rigidbody>();
|
|
}
|
|
|
|
// Update is called once per frame
|
|
void Update()
|
|
{
|
|
Move();
|
|
}
|
|
|
|
void FixedUpdate()
|
|
{
|
|
Rotate();
|
|
}
|
|
|
|
void Move()
|
|
{
|
|
rigidBody.MovePosition(
|
|
transform.position +
|
|
(transform.forward * (run ? runSpeed : speed) * Input.GetAxis("Vertical") * Time.deltaTime) +
|
|
(transform.right * (run ? runSpeed : speed) * Input.GetAxis("Horizontal") * Time.deltaTime)
|
|
);
|
|
}
|
|
|
|
void Rotate()
|
|
{
|
|
transform.Rotate(new Vector3(0, rotateSpeed * Input.GetAxis("Mouse X") * mouseSensitive * Time.deltaTime, 0));
|
|
|
|
if (
|
|
(playerCamera.transform.localEulerAngles.x > 271 && playerCamera.transform.localEulerAngles.x < 360) &&
|
|
playerCamera.transform.localEulerAngles.y == 0 &&
|
|
playerCamera.transform.localEulerAngles.z == 0
|
|
) {
|
|
playerCamera.transform.Rotate(new Vector3(rotateSpeed * -Input.GetAxis("Mouse Y") * mouseSensitive * Time.deltaTime, 0, 0));
|
|
}
|
|
}
|
|
}
|