【发布时间】:2019-12-08 11:46:48
【问题描述】:
这是我的代码:
using UnityEngine;
public class PlayerMovement : MonoBehaviour {
// This is a reference to the Rigidbody component called "rb"
public Rigidbody rb;
public float forwardForce = 4000f;
public float sidewaysForce = 100f;
// We marked this as "Fixed"Update because we
// are using it to mess with physics.
void FixedUpdate()
{
// Add a forward force
rb.AddForce(0, 0, forwardForce * Time.deltaTime);
if( Input.GetKey("d") )
{
rb.AddForce(sidewaysForce * Time.deltaTime, 0, 0, ForceMode.VelocityChange);
}
if( Input.GetKey("a") )
{
rb.AddForce(-sidewaysForce * Time.deltaTime, 0, 0, ForceMode.VelocityChange);
}
}
}
请帮忙。
【问题讨论】:
-
附加一个屏幕截图,选择你的玩家对象,我们的rigidBody组件在Inspector中可见,你的玩家在场景和游戏视图中是焦点。
-
在您尝试时确保游戏视图聚焦。否则,输入将不会被捕获。
标签: c# visual-studio unity3d