PlayerController
PlayerController
Collections;
using System.Collections.Generic;
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;
movementController = GetComponent<CharacterController>(); //
Character Controller
playerCamera = GetComponentInChildren<Camera>(); // Player
Camera
isControlling = true;
ToggleControl(); // Toggle Player control
}
if (Input.GetKeyDown(KeyCode.R))
transform.position = new Vector3(3, 0, 0); // Hit "R" to spawn in
this position
direction.Normalize();
if (movementController.isGrounded) {
velocity = Vector3.zero;
} else {
velocity += -transform.up * (9.81f * 10) * Time.deltaTime; //
Gravity
}
// Camera Look
yaw += Input.GetAxisRaw("Mouse X") * LookSensitivity;
pitch -= Input.GetAxisRaw("Mouse Y") * LookSensitivity;
playerCamera.gameObject.SetActive(isControlling);
#if UNITY_5
Cursor.lockState = (isControlling) ? CursorLockMode.Locked :
CursorLockMode.None;
Cursor.visible = !isControlling;
#else
Screen.lockCursor = isControlling;
#endif