using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class MouseLook : MonoBehaviour
{
public float speedHor = 9f;
public float speedVert = 9f;
public float minVert = -45f;
public float maxVert = 45f;
private float rotationX = 0;
private float rotationY = 0;
// Update is called once per frame
void Update()
{
rotationX -= Input.GetAxis("Mouse Y") * speedVert;
rotationX = Mathf.Clamp(rotationX, minVert, maxVert);
float delta = Input.GetAxis("Mouse X") * speedHor;
float rotationY = transform.localEulerAngles.y + delta;
transform.localEulerAngles = new Vector3(rotationX, rotationY, 0);
}
}
------------------------------
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class PlayerMove : MonoBehaviour
{
// Start is called before the first frame update
private CharacterController charCont;
public float speed;
public float gravity = -9.8f;
void Start()
{
charCont = GetComponent();
}
void Update()
{
float deltaX = Input.GetAxis("Horizontal") * speed;
float deltaZ = Input.GetAxis("Vertical") * speed;
Vector3 movement = new Vector3(deltaX, 0, deltaZ);
movement = Vector3.ClampMagnitude(movement, speed);
movement.y = gravity;
movement *= Time.deltaTime;
movement = transform.TransformDirection(movement);
charCont.Move(movement);
}
}