我正在關注 brackeys 第一人稱運動教程。但我無法讓相機作業。我正確地遵循了教程,但是此代碼不起作用。沒有錯誤,但它不起作用。這是代碼
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class MouseLook : MonoBehaviour
{
public float mouseSensitivity = 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") * 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);
}
}
此代碼沒有給出錯誤,但不起作用。我怎樣才能解決這個問題?
uj5u.com熱心網友回復:
您附加的代碼是正確的。
我建議您再次遵循本教程,并密切注意應附加此腳本的位置。
現在我自己檢查了教程,我通過將相機作為玩家的孩子,將 MouseLook.cs 附加到 Camera 游戲物件,并將玩家游戲物件設定為 MouseLook.cs 中的 Player Body 變數來讓它作業。我建議確保mouseSensitivity變數設定為 100。接下來,如果這不能解決您的問題,它可能意味著很多事情。
首先,您的專案可以取消設定軸“滑鼠 X”和“滑鼠 Y”,這意味著當您移動滑鼠時,它不會記錄滑鼠的移動。
其次,播放器或相機旋轉可能會被其他一些可能導致 MouseLook 旋轉被忽略的行為覆寫。
轉載請註明出處,本文鏈接:https://www.uj5u.com/ruanti/392539.html
上一篇:如何在柏林噪聲上實作偏移?
