Unity - How to write console

21,345

Solution 1

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

Solution 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.
Share:
21,345
zakjma
Author by

zakjma

Updated on October 23, 2020

Comments

  • zakjma
    zakjma over 3 years

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