using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class PCPlayerController : MonoBehaviour
{
private float playerSpeed = 5f;
private float jumpPower = 200f;
private bool onGround;
[SerializeField]private Rigidbody playerRigidbody;
private void Update()
{
GetInput();
}
private void GetInput()
{
if (Input.GetKey(KeyCode.W))
{
transform.localPosition += transform.forward * playerSpeed * Time.deltaTime;
}
if (Input.GetKey(KeyCode.S))
{
transform.localPosition += -transform.forward * playerSpeed * Time.deltaTime;
}
if (Input.GetKey(KeyCode.D))
{
transform.localPosition += transform.right * playerSpeed * Time.deltaTime;
}
if (Input.GetKey(KeyCode.A))
{
transform.localPosition += -transform.right * playerSpeed * Time.deltaTime;
}
if (Input.GetKeyDown(KeyCode.Space))
{
if (onGround == true)
{
playerRigidbody.AddForce(transform.up * jumpPower);
}
}
}
private void OnCollisionEnter(Collision collision)
{
if (collision.gameObject.tag == "Ground")
{
onGround = true;
}
}
private void OnCollisionExit(Collision collision)
{
if (collision.gameObject.tag == "Ground")
{
onGround = false;
}
}
}
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class PCPlayerCameraController : MonoBehaviour
{
private float mouseX, mouseY, xRotation;
[SerializeField]private Transform Player;
[SerializeField]private float mouseSensitivity = 400f;
private void Start()
{
Cursor.lockState = CursorLockMode.Locked;
}
private void Update()
{
mouseX = Input.GetAxis("Mouse X") * mouseSensitivity * Time.deltaTime;
mouseY = Input.GetAxis("Mouse Y") * mouseSensitivity * Time.deltaTime;
xRotation -= mouseY;
xRotation = Mathf.Clamp(xRotation, -90, 90);
transform.localRotation = Quaternion.Euler(xRotation, 0, 0);
Player.Rotate(mouseX * Vector3.up);
}
}