2017-10-05 136 views
-5

我在做滾球教程,我的球沒有移動。我檢查了輸入設置。我甚至設定速度值,甚至添加Time.deltaTime但身體不動如何在unity3D中移動玩家?

using UnityEngine; 
using System.Collections; 

public class PlayerController : MonoBehaviour 
{ 
    public float speed; 
    private Rigidbody rb; 

    void Start() 
    { 
     rb = GetComponent<Rigidbody>(); 
    } 

    void FixedUpdate() 
    { 
     float moveHorizontal = Input.GetAxis("Horizontal"); 
     float moveVertical = Input.GetAxis("Vertical"); 
     Vector3 movement = new Vector3 (moveHorizontal, 0.0f, moveVertical); 
     rb.AddForce (movement * speed); 
    } 
} 
+0

使用UnityEngine;使用System.Collections;公共類PlayerController:MonoBehaviour {公共浮動速度;私人Rigidbody rb; void Start(){rb = GetComponent (); } void FixedUpdate(){float moveHorizo​​ntal = Input.GetAxis(「Horizo​​ntal」); float moveVertical = Input.GetAxis(「Vertical」); Vector3運動=新Vector3(moveHorizo​​ntal,0.0f,moveVertical); rb.AddForce(運動*速度); }} – user38126

+0

請**編輯**你的問題追加代碼。 – zwcloud

+0

您是否將此腳本附加到遊戲對象,並且它是否還有一個隆起的身體? –

回答

1

更多參考的人可能會遇到同樣的問題。

Unity也有PlayerController類,並命名你自己的類,因爲它會導致問題。

只需將類和腳本名稱切換到myPlayerController就可以根據OP解決問題。