[ Solved ] Display transform.position.y in a Text element.

Hello,

I’m trying to display the y position of my OVRCameraRig in a Text object for debugging purpose.
I can get the y value ( debug.log display it correctly ), but impossible to display it inside my text element…

using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;

public class ForForum : MonoBehaviour
{
    public Text debugText;
    public float cameraHeight = 1.75f;
    public Transform realCameraHeight;

    // Start is called before the first frame update
    void Start()
    {
        debugText = GameObject.Find("debugText").GetComponent<Text>();
    }

    // Update is called once per frame
    void Update()
    {
        debugText.text = "realCameraHeight = " + realCameraHeight.position.y.ToString();
        Debug.Log("realCameraHeight = " + realCameraHeight.position.y.ToString());
    }
}

So, I get this in my console : “realCameraHeight = 1.75”
But this on my text element : “realCameraHeight =”

What am I missing?

Your code is correct. My guess is that your Text element is too short.

@JoeStrout Thanks for giving my problem a try.
I checked the size of the text container and it should not be the problem.
The container is larger than the text itself.

May the OVRCameraRig as already a bit of script messing with the y value?

What’s weird is that when I set cameraHeight = 0, the 0 appears correctly in my text element…

It can’t be anything messing with the Y value. realCameraHeight.position.y is a float, so there is no way that realCameraHeight.position.y.ToString() can produce a blank or empty string.

Run the game, and then use the Inspector to inspect your Text element. What do you see in its text property?

Well,
now it display correctly the value in the text element & the inspector pan… weird.
I changed things in my scripts but they were not supposed to be related to this…

Weird weird weird.

Now this is working, I will probably create an other thread for asking about my OVRCameraRigh’s y which for a given value seems to be twice higher when playing the apk in my go…

Thanks @JoeStrout !