我只是在研究Unity5,因爲它是我的學校項目。他們告訴我做一個fps遊戲,我嘗試製作一個fps,讓相機按Q和E旋轉,但我無法用鼠標移動相機。而當我想輸入鼠標時,我根本無法移動我的fps字符。在這裏我的代碼:我如何通過鼠標在鼠標中查看鼠標在fps中的統一性5
using UnityEngine;
public class Player : MonoBehaviour {
private MazeCell currentCell;
private MazeDirection currentDirection;
public void SetLocation (MazeCell cell) {
if (currentCell != null) {
currentCell.OnPlayerExited();
}
currentCell = cell;
transform.localPosition = cell.transform.localPosition;
currentCell.OnPlayerEntered();
}
private void Move (MazeDirection direction) {
MazeCellEdge edge = currentCell.GetEdge(direction);
if (edge is MazePassage) {
SetLocation(edge.otherCell);
}
}
private void Look (MazeDirection direction) {
transform.localRotation = direction.ToRotation();
currentDirection = direction;
}
private void Update() {
if (Input.GetKeyDown(KeyCode.W) || Input.GetKeyDown(KeyCode.UpArrow)) {
Move(currentDirection);
}
if (Input.GetKeyDown(KeyCode.D) || Input.GetKeyDown(KeyCode.RightArrow)) {
Move(currentDirection.GetNextClockwise());
}
if (Input.GetKeyDown(KeyCode.S) || Input.GetKeyDown(KeyCode.DownArrow)) {
Move(currentDirection.GetOpposite());
}
if (Input.GetKeyDown(KeyCode.A) || Input.GetKeyDown(KeyCode.LeftArrow)) {
Move(currentDirection.GetNextCounterclockwise());
}
if (Input.GetKeyDown(KeyCode.Q)) {
Look(currentDirection.GetNextCounterclockwise());
}
if (Input.GetKeyDown(KeyCode.E)) {
Look(currentDirection.GetNextClockwise());
}
}
}
反正我假設你在編碼所以這裏一個建議新:永遠不要使用esle如果你的代碼只是使用if {}否則{如果{...}}。它使事情變得更簡單:D – MrSunshine
然後呢?先生,請告訴我更多 –
sry正在緊迫進入xD – MrSunshine