c# - 短跑、跳跃和主菜单不起作用
问题描述
所以,我是一名使用 c# 和 Unity(刚开始)工作的游戏设计师,我有一个主菜单、冲刺和跳跃,但它们都不起作用。跳转一直有效,直到我制作了主菜单,而冲刺我无法开始工作。
const float walkSpeed = 6.0f;
const float runSpeed = 11.0f;
float moveSpeed = walkSpeed;
if (Input.GetKey(KeyCode.LeftShift))
{
Debug.Log("Run");
// Set current speed to run if shift is down
moveSpeed = runSpeed;
}
else {
// Otherwise set current speed to walking speed
moveSpeed = walkSpeed;
那是我的运行脚本,由于某种原因它不起作用,我不知道为什么,似乎它应该起作用。
if (Input.GetButtonDown("Jump"))
{
velocityY = jumpSpeed;
}
if(controller.isGrounded)
{
velocityY = 0.0f;
}
velocityY += gravity * Time.deltaTime;
那是我的跳跃/重力的东西
public void PlayGame ()
{
SceneManager.LoadScene(SceneManager.GetActiveScene().buildIndex + 1);
}
public void QuitGame ()
{
Debug.Log("Quit");
Application.Quit();
}
}
我看不出如何链接菜单,但不知何故,在进入后,跳转停止工作。
解决方案
你可能想为 Run 做类似的事情。我不知道这是否应该起作用,或者它是否是最好的方法,但我认为它应该起作用。用 () 封装它
if ( (Input.GetKey(KeyCode.A) || Input.GetKey(KeyCode.W) || Input.GetKey(KeyCode.D) ) &&
Input.GetKeyDown(KeyCode.LeftShift) )
{
Debug.Log("Run");
// Set current speed to run if shift is down
moveSpeed = runSpeed;
}
else
{
// Otherwise set current speed to walking speed
moveSpeed = walkSpeed;
}
推荐阅读
- python - 即使 if 语句为假,我的 python 代码仍然运行
- python - Python:验证列条目是否与所需格式匹配
- javascript - 如果不支持,是否有任何可能的方法将 html 属性添加到 primefaces 组件?
- java - 使用 SSLEngine 使用为内部网络位置签名的证书
- python - django:访问请求会话对象内的字典键
- vega-lite - 滑块滑到指定年份时如何禁用配色方案并启用配色方案?
- python - TypeError:“模块”对象不可调用 Python3
- mysql - 我正在尝试将 1 列分解为多列
- c# - 如何在 Unity 运行时使用新的输入系统切换动作映射?
- mysql - 在不使用 out 参数的情况下将存储过程输出捕获到变量中