using System.
Collections;
using [Link];
using UnityEngine;
[RequireComponent(typeof(CharacterController))]
public class PlayerController : MonoBehaviour
{
public float MinYaw = -360;
public float MaxYaw = 360;
public float MinPitch = -60;
public float MaxPitch = 60;
public float LookSensitivity = 1;
public float MoveSpeed = 10;
public float SprintSpeed = 30;
private float currMoveSpeed = 0;
protected CharacterController movementController;
protected Camera playerCamera;
protected bool isControlling;
protected float yaw;
protected float pitch;
protected Vector3 velocity;
protected virtual void Start() {
movementController = GetComponent<CharacterController>(); //
Character Controller
playerCamera = GetComponentInChildren<Camera>(); // Player
Camera
isControlling = true;
ToggleControl(); // Toggle Player control
}
protected virtual void Update() {
if ([Link](KeyCode.R))
[Link] = new Vector3(3, 0, 0); // Hit "R" to spawn in
this position
Vector3 direction = [Link];
direction += [Link] * [Link]("Vertical");
direction += [Link] * [Link]("Horizontal");
[Link]();
if ([Link]) {
velocity = [Link];
} else {
velocity += -[Link] * (9.81f * 10) * [Link]; //
Gravity
}
if ([Link]([Link])) { // Player can sprint by holding
"Left Shit" keyboard button
currMoveSpeed = SprintSpeed;
} else {
currMoveSpeed = MoveSpeed;
}
direction += velocity * [Link];
[Link](direction * [Link] * currMoveSpeed);
// Camera Look
yaw += [Link]("Mouse X") * LookSensitivity;
pitch -= [Link]("Mouse Y") * LookSensitivity;
yaw = ClampAngle(yaw, MinYaw, MaxYaw);
pitch = ClampAngle(pitch, MinPitch, MaxPitch);
[Link] = new Vector3(pitch, yaw, 0.0f);
}
protected float ClampAngle(float angle) {
return ClampAngle(angle, 0, 360);
}
protected float ClampAngle(float angle, float min, float max) {
if (angle < -360)
angle += 360;
if (angle > 360)
angle -= 360;
return [Link](angle, min, max);
}
protected void ToggleControl() {
[Link](isControlling);
#if UNITY_5
[Link] = (isControlling) ? [Link] :
[Link];
[Link] = !isControlling;
#else
[Link] = isControlling;
#endif