Skip to content

Instantly share code, notes, and snippets.

@donovankeith
Created February 3, 2022 18:08
Show Gist options
  • Select an option

  • Save donovankeith/33eb4246f2c8902eb83d2afe57c0d7d9 to your computer and use it in GitHub Desktop.

Select an option

Save donovankeith/33eb4246f2c8902eb83d2afe57c0d7d9 to your computer and use it in GitHub Desktop.

Revisions

  1. donovankeith created this gist Feb 3, 2022.
    39 changes: 39 additions & 0 deletions PositionInspector.cs
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,39 @@
    // 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 <[email protected]>
    // 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();
    }
    }