c# - 为什么球在越过边缘时(即比赛结束)没有下降?
问题描述
这里的程序没有使用以下行更新:rb.velocity = new Vector3 (0, -25f, 0); 球在通过边缘时应该会掉下来,但它会卡在边缘..我还在边缘和球之间产生零摩擦..
void Start () {
started = false;
gameOver = false;
}
void Update () {
if (!started) {
if (Input.GetMouseButtonDown (0)) {
rb.velocity = new Vector3 (speed, 0, 0);
started = true;
}
}
Debug.DrawRay (transform.position, Vector3.down, Color.red);
if (!Physics.Raycast (transform.position, Vector3.down, 1f)) {
gameOver = true;
rb.velocity = new Vector3 (0, -25f, 0);
}
if (Input.GetMouseButtonDown (0) && !gameOver)
{
SwitchDirection ();
}
}
void SwitchDirection(){
if (rb.velocity.z > 0)
{
rb.velocity = new Vector3 (speed, 0, 0);
}
else if (rb.velocity.x > 0){
rb.velocity = new Vector3 (0, 0, speed);
}
}
解决方案
推荐阅读
- ios - Ionic 4 在 iOS 设备上运行应用程序时出现电容器错误
- java - 用位于该字符串末尾的整数字符替换 URL 字符串
- javascript - 在附加到字符串时在 JavaScript 中制作原型函数应该多次修改并打印它
- php - 致命错误:ext/standard/php_smart_str.h:安装 yaml 1.3.2 时没有这样的文件或目录
- java - 三元运算符与 Map NullPointerException Java
- flutter - 我的 Flutter 有问题,我需要跳过错误而不更新 intl 或 flutter_localizations
- python - 如何将字符串中多个单词的第一个和第四个字母大写?
- azure - 如何低成本学习 Azure SQL 数据库?
- directory - 如何测试 Apple Script 中存在的文件夹?
- android - 当 NavHost 不在 Activity 中时,Android Navigation findNavController