c# - 为什么我的子弹没有使用 rb.velocity 移动?
问题描述
我正在尝试自己制作一个小型太空射击游戏,但在尝试制作子弹预制件时遇到了问题。我在 start 方法中设置它的速度,当我按下 play 时它根本没有移动。
public float speed;
Rigidbody2D rb;
void Start()
{
rb = GetComponent<Rigidbody2D>();
rb.velocity = transform.forward * speed;
}
我也在我的播放器脚本中使用 rb.velocity 来移动他,它工作得很好。
解决方案
它不工作,因为你把 rb.velocity = transform.forward * speed; 进入启动功能。
试试这个脚本
public float speed;
Rigidbody2D rb;
void Start()
{
rb = GetComponent<Rigidbody2D>();
}
void Update()
{
rb.velocity = transform.forward * speed;
}
推荐阅读
- javascript - 如何通过单击删除它..?
- cloudflare - Cloudflare Status API - 哪个组件检查问题?
- css - React styled-component,动画:反转两个div的位置
- php - 如何根据用户名获取角色名?
- angular - Angular 6 网站无法在 IE 上运行,但可以在所有浏览器上本地运行
- regex - 使正则表达式在所需字符串的中间接受连字符/破折号
- elasticsearch - 弹性栈的 Basic Free(不是 OSS)docker 镜像能否用于商业组织的产品开发?
- python - 给定每个元素的最大量值和元素的最大总和的元组组合
- android - 如何用另一种布局颜色填充布局角
- angular - 当我将“changeDetectionStrategy”添加到我的应用程序时出现错误