【问题标题】:Unity - How to write consoleUnity - 如何编写控制台
【发布时间】:2020-10-23 12:52:29
【问题描述】:

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

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);
    }

【问题讨论】:

    标签: c# unity3d console mouseevent


    【解决方案1】:

    使用 Debug 类写入 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);
    }
    

    【讨论】:

      【解决方案2】:

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

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

      【讨论】:

        猜你喜欢
        • 2018-12-16
        • 2011-07-09
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2012-06-24
        • 1970-01-01
        • 2019-08-17
        相关资源
        最近更新 更多