2016-04-03 9 views
0

私の学校のプロジェクトであるのでUnity5を探しています。彼らは私にfpsゲームを作ろうと言っていました。カメラをQとEで回転させるfpsを作ろうとしましたが、マウスでカメラを動かすことはできません。マウスを入力したいときは、自分のfps文字を動かすことはできません。ここに私のコードは:すべてのどのように私はマウスでカメラのビューを1フレームで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()); 
    } 
} 

}

答えて

0

まず、あなたの更新機能では、「他の場合」■remooveし、「もし」単純に置き換える必要があります。 ifステートメントの1つが真であるとすぐに次の関数がスキップされるためです。それを修正する必要があります 。

+0

を{...}}。それは物事をはるかに単純化する:D – MrSunshine

+0

それから何???ミスター、私に教えてください –

+0

sryはすぐに入力を押していたxD – MrSunshine

0

この試す:{}他{かの場合だけ使用して、あなたのコード内であれば、これまでesleを使用しないでください:とにかく、私はあなたがそう、ここで1つの提案をコーディングに慣れていないと仮定し

public class Player : MonoBehaviour { 
//Position of mouse since last change in viewdirection 
private float mousePosLast; 

//Tollerance of mouse input 
//this is optional but makes the the input not that sensitive 
public float mouseTollerance; 

//sets the correct position of mouse on start 
public void Start() { 
    mousePosLast = Input.mousePosition.x; 
} 


public void Update() { 
    /* 
    ...other update code... 
    */ 

    if (Input.GetKeyDown(KeyCode.Q)) { 
       Look(currentDirection.GetNextCounterclockwise()); 
     } 
     if (Input.GetKeyDown(KeyCode.E)) { 
      Look(currentDirection.GetNextClockwise()); 
     } 

    //check if change in mouse position is big enougth to trigger camera rotation 
    if(Mathf.Abs(Input.mousePosition.x - mousePosLast) > mouseTollerance){ 
     //check whether to turn right or left 
     if(Input.mousePosition.x - mousePosLast > 0){ 
      Look(currentDirection.GetNextCounterclockwise()); 
     }else{ 
      Look(currentDirection.GetNextClockwise()); 
     } 
    } 
} 

private void Look (MazeDirection direction) { 
     transform.localRotation = direction.ToRotation(); 
     currentDirection = direction; 

    //set mousePosLast to current mouseposition on every change -> avoids strange effects 
    mousePosLast = Input.mousePosition.x; 
} 

}

+0

うわー、それはゲームの壁を見れますが、とにかく感謝しています。 –

+0

多分あなたはあなたのコード全体を調べなければなりません。あなたのPlayerクラスによって直接引き起こされないいくつかの問題があるかもしれません。 – MrSunshine

+0

ああこれは私が今持っているすべてのコードです –

関連する問題