You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Unity中Flappy Bird按空格键鸟无响应问题求助及解决

问题与解决:Unity复刻Flappy Bird输入无响应
  • 背景:刚入门Unity,跟着教程复刻Flappy Bird,将Player脚本挂载到小鸟对象后,键盘、鼠标/触摸输入均无响应,核对教程步骤、找程序员姐姐排查都未发现问题。
  • 已解决:问题根源是未将刚体组件的Body Type设置为Kinematic,调整后输入操作恢复正常。

Player脚本代码

public class Player : MonoBehaviour
{
    private Vector3 direction;
    public float gravity = -9.8f;
    public float strength = 5f;

    private void Update()
    {
        if (Input.GetKeyDown(KeyCode.Space) || Input.GetMouseButtonDown(0))
        {
            direction = Vector3.up * strength;

//我试过加Debug.Log,能正常输出(补充说明)
        }

        if (Input.touchCount > 0)
        {
            Touch touch = Input.GetTouch(0);

            if (touch.phase == TouchPhase.Began)
            {
                direction = Vector3.up * strength;
            }
        }

        direction.y += gravity * Time.deltaTime;
        transform.position += direction * Time.deltaTime;
    }
}

内容的提问来源于stack exchange,提问作者NamNam

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.07.23 07:22:07