Unity - 如何编写控制台

Unity - How to write console

我在我的 unity 项目中添加了一个 AR 相机。我将 vuforia sdk 用于 AR 功能。我想处理 mouse/finger 单击屏幕并获取屏幕图像上的像素位置。我写下面的代码。为了检查像素值,我尝试将它们写在控制台上。但我什么也没看到。 AR 相机有一个名为 DefaultTrackableEventHandler.cs 的 .cs 文件。我修改了它。我 运行 我的应用程序是 android 真实设备。

DefaultTrackableEventHandler.cs

if (Input.touchCount > 0 && Input.GetTouch (0).phase == TouchPhase.Began) {
        float x = Input.GetTouch(0).position.x;
        float y = Input.GetTouch(0).position.y;
        print("x " + x + " - y " + y);
    }

使用 Debug class 写入 Unity 控制台。

例如:

if (Input.touchCount > 0 && Input.GetTouch (0).phase == TouchPhase.Began) {
    float x = Input.GetTouch(0).position.x;
    float y = Input.GetTouch(0).position.y;
    Debug.Log("x " + x + " - y " + y);
}

使用Debug.Log(object)。 补充说明:

  1. 您可以使用插值字符串来构造复杂的消息,例如:
Debug.Log($"a={a}, b={b}, c={Time.deltaTime}");
  1. Debug.Log 还会打印当前堆栈跟踪,因此您无需自行寻找打印方法。