Skip to content

Instantly share code, notes, and snippets.

@donovankeith
Created February 3, 2022 18:08
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save donovankeith/33eb4246f2c8902eb83d2afe57c0d7d9 to your computer and use it in GitHub Desktop.
Save donovankeith/33eb4246f2c8902eb83d2afe57c0d7d9 to your computer and use it in GitHub Desktop.
Unity Script for Inspecting Position of an Object and Printing to GUI
// PositionInspector.cs
// Prints the position of `targetObject` to the `text` field
// of a Text Mesh Pro text object.
//
// ## Usage
//
// 1. Create a Text Mesh Pro Text Game Object (or select one if it already exists).
// 2. Add this script.
// 3. Link the object whose position you want to inspect in the "targetObject" field.
// 4. Press Play
//
// Written by Donovan Keith <dkeith@calarts.edu>
// License CC0, No Rights Reserved
// https://creativecommons.org/publicdomain/zero/1.0/
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using TMPro;
public class PositionInspector : MonoBehaviour
{
public GameObject targetObject;
private TextMeshProUGUI countText;
private Vector3 pos;
// Start is called before the first frame update
void Start()
{
countText = GetComponent<TextMeshProUGUI>();
}
// Update is called once per frame
void Update()
{
pos = targetObject.transform.position;
countText.text = pos.ToString();
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment