2017-10-05 138 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解决问题。