Display Player Coordinates on Simple GUIText

Hey Everyone -

Novice here - of course. I’m using Unity 5, and am looking to display on screen the coordinates of a player using a FPS camera. The main reason is I’m using a camera path animator to fly around a terrain scene I built for class, and think by logging coordinates via walking around in FP will make placing my camera path waypoints a lot easier.

What I have done:

-Created new empty game object
-Added Component → Rendering → GUIText
-Added Component → New Script ->C#

Now I of course searched around to find a solution and found this:

function OnGUI () {
GUI.Label (Rect (10,120,500,100), "X = " + transform.position.x + " Y= " + transform.position.y + "Z= " + transform.position.z);

Which is great! But I am not a strong C# programmer by any means, but I do know this needs a Player variable of some sort yet. So please, could anyone simply direct me, or mind posting the code needed to make player coordinates appear on the screen. This doesn’t have to be pretty or anything, I just need to write down the data as I walk around in FP. (unless you want brownie points and know of a way to log coordinates into a .txt file on button press… hahaha Thanks guys!

@chaosUnseen the playerpositionlogger script link doesn’t work anymore, is there another way to find the script?

So the guys at StackOverFlow helped me out and figured I would share his way of logging coordinates through the console. But as elementary as this sounds - THE TRUE solution was present all along for me. I simply selected the FPC in the hierarchy during PLAY and boom inspector gave me what I needed in the transform spot. Duh. But here’s JuHong Jung’s solution as described:

-Create new GameObject(GUIText) and make it’s parent with your player game object. Now GUIText game object will follow your player object automatically

-Add new script(PlayerPositionLogger.cs). to GUIText game object.

-Find player script on void Start() on PlayerPositionLogger.cs or declare public Player player; and link player object on editor.

-Update content of GUIText with player object.

*His PlayerPositionLogger script can be found here

Thanks anyway to all who looked and hopefully this will help someone someday.

Yeah, i’d like that script too.

@Lagoons and @c15leis
I quickly wrote a script you might find useful. I used a simple cube as the player and it is quite easy to do.

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

public class PositionLogger : MonoBehaviour {
	public GameObject myCube;
	public Text myText;
	// Use this for initialization
	void Start () {
	// Update is called once per frame
	void Update () {
		if (Input.GetKeyDown ("w")) {
			myCube.transform.position += transform.forward;
		} else if (Input.GetKeyDown ("s")) {
			myCube.transform.position -= transform.forward;
		} else if (Input.GetKeyDown ("d")) {
			myCube.transform.position += transform.right;
		} else if (Input.GetKeyDown ("a")) {
			myCube.transform.position -= transform.right;
		LogMyPosition ();
	public void LogMyPosition(){
		myText.text = "MY POSITION IS: " + myCube.transform.position;