Search code examples
c#unity-game-engineconsolemouseevent

Unity - How to write console


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

Solution

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