I have a GameObject that is Instantiated at Runtime. Here I want to attach 3D Text to that Instantiated GameObject and that Text move along with the moving GameObject.
Here is my Code:
void Update()
{
GameObject gameObj = (GameObject)GameObject.Instantiate(myPrefab);
GameObject _3d = (GameObject)GameObject.Find("txt");
gameObj.transform.position = new Vector3(Random.Range(this.transform.position.x - 1, this.transform.position.x + 1), Random.Range(this.transform.position.y - 0.1f, this.transform.position.y + 0.1f), 0);
// Here I tried to attach 3D Text
// My Code is
/*
TextMesh t;
t.transform.position = gameObj.transform.position;
t = _3d.GetComponent<TextMesh>();
//t = (TextMesh)_3d.GetComponent(typeof(TextMesh));
t.text = "My New Text";
*/
}
But this doesn’t add any Text to the gameObj. Help is needed.
Thanks in Advance.