Hello everyone, sorry to ask such a basic question but I’m not sure what to do here
I’m using this script Unity - Scripting API: Object.ToString (unity3d.com) to show the name of the game object as text
//This script changes Text to the name of the GameObject with the script attached
//Attach this script to a GameObject
//Attach a Text GameObject in the Inspector (Create>UI>Text)
using UnityEngine;
using UnityEngine.UI;
public class Example : MonoBehaviour
{
public Text m_Text;
private void Start()
{
//Check that the Text is attached in the Inspector
if (m_Text != null)
//Change the Text to show the GameObject's name
m_Text.text = "GameObject Name : " + gameObject.ToString();
}
}
“This script changes Text to the name of the GameObject with the script attached”, But it’s only showing up as "GameObject Name : " on the UI and not the name of the object in the inspector
UPDATE:
That was fixed by, changing this line
m_Text.text = "GameObject Name : " + gameObject.ToString();
to this
m_Text.text = gameObject.ToString();
but now it’s showing “(Unityengine.gameobject)” after the text
Imgur: The magic of the Internet
Does anyone know how to Only show the text name of the Object?