Created
February 3, 2022 18:08
-
-
Save donovankeith/33eb4246f2c8902eb83d2afe57c0d7d9 to your computer and use it in GitHub Desktop.
Unity Script for Inspecting Position of an Object and Printing to GUI
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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(); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment