Unity - How to write console
Asked Answered
U

2

10

I add an AR camera my unity project. I use vuforia sdk for AR functions. I want to handle mouse/finger click on screen and get pixel position on screen image. I write below code. To check pixel values, I try to write them on the console. But I don't see anything. AR camera has a .cs file named DefaultTrackableEventHandler.cs. I modified it. I run my application an android real device.

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);
    }
Unintelligent answered 24/4, 2015 at 7:41 Comment(0)
V
13

Use the Debug class to write to the Unity console.

E.g.:

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);
}
Vonnie answered 24/4, 2015 at 7:44 Comment(0)
I
2

Use Debug.Log(object). Additional notes:

  1. you may use interpolation string to construct a complex message, such as:
Debug.Log($"a={a}, b={b}, c={Time.deltaTime}");
  1. Debug.Log also prints the current stack trace, so you needn't find a way to print that on your own.
Indifferent answered 23/10, 2020 at 4:52 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.