Making text popup in the right place when called

I’m having some problems with having a piece of text popup where I want it to.

I’m using the following code on a monobehavior attached to a game object where I want the text to appear on top of my game object.

How should I arrange it so that my text appears exactly where I want it to here. I have a feeling its a strange mismatch between rect transform position and the game objects transform position.

public void PopupText(string message)
{
	var text = GameObject.Instantiate<GameObject> (DamageText);
	text.GetComponent<Text>().text = message;
	text.transform.position = this._rigidbody.position; //Doesn't Work

	text.transform.SetParent (GameObject.Find ("Canvas").transform, false); //Must be on Canvas
	
}

You have few options:

First try this:

 public void PopupText(string message)
 {
     var text = GameObject.Instantiate<GameObject> (DamageText);
     text.GetComponent<Text>().text = message;

     // Find red player and set its transform position to text.
     GameObject redPlayer = GameObject.FindGameObjectWithTag("RedPlayer");
     text.transform.position = redPlayer.transform.position; 

     text.transform.SetParent (redPlayer.transform, false); //Must be on Canvas
 }

I am assuming you have this red player tagged with tag “RedPlayer”.

Also, instead of creating this text every time, add this text one time to the redplayer object and show/hide them set/reset as per the need using GetComponent.