using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class PlayerMouseLook : MonoBehaviour
{
public float mouseSensitivity = 1000f;
public Transform playerBody;
float xRotation = 0f;
public GameObject checker;
bool clicked;
// Start is called before the first frame update
void Start()
{
//Cursor.lockState = CursorLockMode.Locked;
}
// Update is called once per frame
void Update()
{
if (Input.GetKey(KeyCode.LeftAlt))
{
if (Input.GetMouseButtonDown(0))
{
clicked = true;
}
if (!clicked)
{
checker.SetActive(true);
SetCheckerPosition();
}
}
else
{
clicked = false;
checker.SetActive(false);
LookRotation();
}
}
void LookRotation()
{
float mouseX = Input.GetAxis("Mouse X") * mouseSensitivity * Time.deltaTime;
float mouseY = Input.GetAxis("Mouse Y") * mouseSensitivity * Time.deltaTime;
xRotation -= mouseY;
xRotation = Mathf.Clamp(xRotation, -90f, 90f);
transform.localRotation = Quaternion.Euler(xRotation, 0f, 0f);
playerBody.Rotate(Vector3.up * mouseX);
}
void SetCheckerPosition()
{
Ray ray = Camera.main.ScreenPointToRay(Input.mousePosition);
if (Physics.Raycast(ray, out RaycastHit raycastHit))
{
checker.transform.position = raycastHit.point;
}
}
}
댓글 없음:
댓글 쓰기