c# - 我如何添加一行来告诉代码我希望平台在关卡循环完成后加速/
问题描述
public class PlatformMoving : MonoBehaviour
{
public float speed = 1.5f; //How fast the platforms are moving
// use this for initialization
void Start()
{
}
// Update is called once per frame
void Update()
{
// Every frame we look at the position of the ground and it is moved to the left
transform.position = transform.position - (Vector3.right * speed * Time.deltaTime);
// If the position of the ground is off the left of the screen
if (transform.position.x <= -13.05f)
{
// Move it to the far right of the screen
transform.position = transform.position + (Vector3.right * 53.3f);
}
}
}
解决方案
假设您正在谈论的循环是注释后面的行// If the position of the ground is off the left of the screen
。速度的增加将在其后的if
语句中指定,因为这是循环发生的地方。
我会避免称它为loop
btw,只是因为它在浏览代码时会搜索 a或循环for
,当不存在时会导致混乱。while
foreach
我已经在您的代码中评论了它所在的位置。
public class PlatformMoving : MonoBehaviour
{
public float speed = 1.5f; //How fast the platforms are moving
// use this for initialization
void Start()
{
}
// Update is called once per frame
void Update()
{
// Every frame we look at the position of the ground and it is moved to the left
transform.position = transform.position - (Vector3.right * speed * Time.deltaTime);
// If the position of the ground is off the left of the screen
if (transform.position.x <= -13.05f)
{
// Move it to the far right of the screen
transform.position = transform.position + (Vector3.right * 53.3f);
// Increase speed here
// speed += x;
}
}
}
推荐阅读
- c# - 可以在控制台应用程序中访问 API,但不能访问 ASP.Net MVC 应用程序
- c# - 如何在 Open XML 中使项目符号变大?
- angular - 使用带有 *ngFor 的 _.groupby() lodash - 对象错误
- javafx - 如何在javafx中按下一个键(ENTER)后选择下一个文本字段?
- highcharts - 在 highcharts 版本 5 中使用 highcharts-more
- python - 从 pandas .value_counts() 获取系列的第一个元素
- vba - 如何使用 VBA 将记录从 rs1 移动到 rs2 (ADODB.Recordsets)?
- javascript - 为什么 fetch 函数说我必须使用绝对 url,即使我设置了代理?
- r - 在多个栅格上绘制多个 shapefile
- c# - 如何在访问数据库与 2 个日期之间进行搜索?