【问题标题】:Print/Debug.log does not show output in Unity console [closed]Print/Debug.log 不在 Unity 控制台中显示输出 [关闭]
【发布时间】:2020-10-29 20:57:37
【问题描述】:

我是 Unity 的新手。当我按下时,打印不起作用。
我已将脚本附加到角色上。
我做错了什么?

using UnityEngine;

public class Player : MonoBehaviour
{
    public Animator Anim;

    void Start()
    {
        Anim = GetComponent<Animator>();
    }

    void Update()
    {
        if (Input.GetKeyDown("1"))
        {
            print("I pressed 1");
        }
    }
}

谢谢。

【问题讨论】:

  • 我用Unity已经有一段时间了,但您不需要指定密钥代码吗?所以你的代码是if(Input.GetKeyDown(KeyCode.Alpha1))?取自这里docs.unity3d.com/ScriptReference/KeyCode.html
  • @Mkalafut 不幸没有工作。
  • 为我工作。寻求错误帮助的问题必须包含minimal reproducible example。投票结束,直到问题正文中包含一个。
  • 我的问题已在以下答案的评论中解决。我不明白,为什么要投反对票?
  • @mrbengi 这对未来的访问者没有帮助,因为它没有以有用的方式描述问题。这个问题甚至没有解释你按的是哪个键。当我按下 number row. 中的 1 键时,它对我有用

标签: unity3d


【解决方案1】:

改用 Debug.Log("I press 1")

if (Input.GetKeyDown(KeyCode.Space)) { Debug.Log("Space key was pressed."); }

【讨论】:

  • 它也不行
  • if (Input.GetKeyDown(KeyCode.Space)) { Debug.Log("空格键被按下。"); } 这与 Space 合作吗?
  • 或者试试 KeyCode.Keypad1
  • 空格键有效,谢谢。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2015-02-22
  • 1970-01-01
  • 1970-01-01
  • 2018-09-14
  • 2014-09-06
  • 1970-01-01
  • 2020-01-12
相关资源
最近更新 更多