KYJxierang/Assets/New Folder/Player.cs
2024-12-23 06:02:30 +08:00

43 lines
872 B
C#
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class Player : MonoBehaviour
{
public float moveSpeed;//移动速度
public float rotateSpeed;//旋转角度
private float angleY;//左右看角度绕Y轴转
private float angleX;//上下看角度绕x轴转
void Start()
{
}
void Update()
{
PlayerMove(); LookAround();
}
private void PlayerMove()
{
}
private void LookAround()
{
float mouseX = Input.GetAxis("Mouse X");
float lookHAngleY = mouseX* rotateSpeed;
angleY=angleY+ lookHAngleY;
float mouseY =- Input.GetAxis("Mouse Y");
float lookVAngleX = mouseY * rotateSpeed;
angleX = Mathf.Clamp(angleX + lookVAngleX, -60, 60);
transform.eulerAngles = new Vector3(angleX, angleY, transform.eulerAngles.z);
}
}