Unity 和 C# 有点新,试图让相机四处移动以让用户看到房间。这有点像视觉小说,所以我只希望房间的特定部分可见。
这就是我到目前为止所拥有的。它工作得很好,但它从最小角度开始,我希望它从我在检查器中设置的坐标开始。
我尝试创建一种方法,该方法将以确切的值启动它,但这不起作用
public class CameraMovement : MonoBehaviour
{
// Start is called before the first frame update
public float mouseSensitivity = 70f;
public float yawMax = 90f;
public float yawMin = -90f;
public float pitchMax = 90f;
public float pitchMin = -90f;
private float yaw = 0.0f;
private float pitch = 0.0f;
void Start()
{
Cursor.lockState = CursorLockMode.Locked;
SetCameraStartingPosition();
}
// Update is called once per frame
void Update()
{
HandleMouseMovement();
}
void SetCameraStartingPosition() {
transform.eulerAngles = new Vector3(0.02f, 0.292f, -0.323f);
}
void HandleMouseMovement() {
yaw += mouseSensitivity * Input.GetAxis("Mouse X") * Time.deltaTime;
pitch -= mouseSensitivity * Input.GetAxis("Mouse Y") * Time.deltaTime;
yaw = Mathf.Clamp(yaw, yawMin, yawMax);
pitch = Mathf.Clamp(pitch, pitchMin, pitchMax);
transform.eulerAngles = new Vector3(pitch, yaw, 0.0f);
}
}