错误消息说“类型或名称空间定义,或者预期的文件结束”
我不确定我的代码是怎么回事,请记住我刚刚开始编码。请帮忙!
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public RigidBody rb
{}
public float forwardForce = 2000f;
public float sidewaysForce = 2000f;
void Update()
{
rb.AddForce(0, 0, forwardForce * Time.deltaTime);
if (Input.GetKey("w"))
{
rb.AddForce(500 * Time.deltaTime, 0, 0);
}
}
}
I'm not sure what's up with my code and please bare in mind I have just started coding. please help!
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public RigidBody rb
{}
public float forwardForce = 2000f;
public float sidewaysForce = 2000f;
void Update()
{
rb.AddForce(0, 0, forwardForce * Time.deltaTime);
if (Input.GetKey("w"))
{
rb.AddForce(500 * Time.deltaTime, 0, 0);
}
}
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
对于您提到的错误,您需要在代码中删除最后的
}
。您还需要声明命名空间
和class
,因为没有这些就无法声明字段和方法。您还应该初始化刚性
。最后,您的代码应该看起来像这样:For the error you mention to go away you need to remove the last
}
in your code. You will also need to declare anamespace
and aclass
as you cannot declare fields and methods without those. You should also initialize yourRigidBody
. In the end your code should look something like this: