Position of object

How to display the z position of and object (character) on canvas

you need to create Canvas UI from Scene Hierarchy. Then create TextUI and attach it to your canvas like below image.

Then in your script, declare public variable to store your text that you create from the editor. Back to the editor, drag the text from hierarchy to the text variable of your script appeared in the inspector. Now, open your script and write the following code.

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


public class CameraScript : MonoBehaviour {

    public Text m_Text = null;
    public GameObject m_PlayerObj = null;

    void Start () {

        m_Text.text = m_PlayerObj.transform.position.z.ToString();
    }
  
    // Update is called once per frame
    void Update () {

        m_Text.text = m_PlayerObj.transform.position.z.ToString();
      
    }
}
1 Like

Thank you that helped a lot