簡體   English   中英

如何在unity3D中移動玩家?

[英]How to move a player in unity3D?

我正在做滾球教程,但我的球沒有移動。 我檢查了輸入設置。 我什至設置了速度值,甚至添加了 Time.deltaTime 但身體沒有移動

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); 
    } 
} 

供可能遇到相同問題的人進一步參考。

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

根據 OP,簡單地將類和腳本名稱更改為myPlayerController之類的名稱即可解決該問題。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM