【发布时间】:2020-02-16 00:15:52
【问题描述】:
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class MouseLock : MonoBehaviour
{
public float mouseSensetivity = 100f;
public Transform playerBody;
float xRotation = 0f;
// Start is called before the first frame update
void Start()
{
Cursor.lockState = CursorLockMode.Locked;
}
// Update is called once per frame
void Update()
{
float mouseX = Input.GetAxis("Mouse X") * mouseSensetivity * Time.deltaTime;
float mouseY = Input.GetAxis("Mouse Y") * mouseSensetivity * Time.deltaTime;
xRotation -= mouseY;
xRotation = Mathf.Clamp(xRotation, -90f, 90f);
transform.localRotation = Quaternion.Euler(xRotation, 0f, 0f);
playerBody.Rotate(Vector3.up * mouseX);
}
}
我真的没有看到任何问题,您可以看到代码仅在一个对象上,这是我从教程中获得的相机。
【问题讨论】:
-
除非绝对必要,否则请不要将信息共享为图像。见:meta.stackoverflow.com/questions/303812/…
标签: c# unity3d game-development