gpt4 book ai didi

unity3d - 统一: The variable rb of Movement has not been assigned

转载 作者:行者123 更新时间:2023-12-05 00:59:15 27 4
gpt4 key购买 nike

我是 Unity 新手,正在关注 this tutorial .当我尝试执行代码时遇到的错误应该是左右移动播放器是:

UnassignedReferenceException: The variable rb of Movement has not been assigned.
You probably need to assign the rb variable of the Movement script in the inspector.
UnityEngine.Rigidbody.AddForce (UnityEngine.Vector3 force, UnityEngine.ForceMode mode) <0x3cc39790 + 0x00062> in <31353b3f2d2e434595cbfe07fbec4072>:0
UnityEngine.Rigidbody.AddForce (System.Single x, System.Single y, System.Single z) (at C:/buildslave/unity/build/Runtime/Dynamics/ScriptBindings/Dynamics.bindings.cs:176)
Movement.FixedUpdate () (at Assets/Movement.cs:17)

由于玩家不动,如何解决?

运动脚本:

   using UnityEngine;

public class Movement : MonoBehaviour
{

// This is a reference to the Rigidbody component called "rb"
public Rigidbody rb;
public float forwardForce = 2000f; // Variable that determines the forward force
public float sidewaysForce = 500f; // Variable that determines the sideways force

// 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")) // If the player is pressing the "d" key
{
// Add a force to the right
rb.AddForce(sidewaysForce * Time.deltaTime, 0, 0);
}

if (Input.GetKey("a")) // If the player is pressing the "a" key
{
// Add a force to the left
rb.AddForce(-sidewaysForce * Time.deltaTime, 0, 0);
}
}
}

最佳答案

您没有为 rb 设置任何内容。在检查器中,您可以通过单击“this”(查看图片)选择要使用的刚体

enter image description here

关于unity3d - 统一: The variable rb of Movement has not been assigned,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/54403073/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com