-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);
}
}
使用UnityEngine;使用System.Collections;公共类PlayerController:MonoBehaviour {公共浮动速度;私人Rigidbody rb; void Start(){rb = GetComponent (); } void FixedUpdate(){float moveHorizontal = Input.GetAxis(“Horizontal”); float moveVertical = Input.GetAxis(“Vertical”); Vector3运动=新Vector3(moveHorizontal,0.0f,moveVertical); rb.AddForce(运动*速度); }} – user38126
请**编辑**你的问题追加代码。 – zwcloud
您是否将此脚本附加到游戏对象,并且它是否还有一个隆起的身体? –