[英]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.