using System.Collections; using System.Collections.Generic; using UnityEngine; using UnityEngine.AI;
public class PlayerMovement : MonoBehaviour { public NavMeshAgent agent;
// Start is called before the first frame update void Start() { agent = GetComponent<NavMeshAgent>(); }
// Update is called once per frame void Update() { // Click to Move if(Input.GetMouseButtonDown(0)){ RaycastHit hit; Ray ray = Camera.main.ScreenPointToRay(Input.mousePosition); if(Physics.Raycast(ray, out hit, Mathf.Infinity)){ agent.SetDestination(hit.point); } } } }
using System.Collections; using System.Collections.Generic; using UnityEngine;
public class CameraLook : MonoBehaviour { public float mouseSensitivity = 100f; public float keySensitivity = 100f; public Transform player = null; private float xRotation = 0f;
// Start is called before the first frame update void Start() { }
// Update is called once per frame void Update() { // Get mouse position float mouseX = Input.GetAxis("Mouse X") * mouseSensitivity * Time.deltaTime; float mouseY = Input.GetAxis("Mouse Y") * mouseSensitivity * Time.deltaTime;
// Rotate camera up and down xRotation -= mouseY; xRotation = Mathf.Clamp(xRotation, -30f, 30f); transform.localRotation = Quaternion.Euler(xRotation, 0f, 0f);
// Rotate player left and right player.Rotate(Vector3.up * (mouseX + keyX)); } }