Unity 5 - UI Text

Hi guys! I hope you can help me with a simple problem. I’m trying to simulate a “damage score” text on top of the player’s head when it gets hit by an object.

But the problem is I can’t make the position when instantiating it right on top of the player.

This is my code:

using UnityEngine;
using UnityEngine.UI;
using System.Collections;
using System.Collections.Generic;

public class Rotator : MonoBehaviour {

	public GameObject damage;

        //button clicked
	public void onDamage(){
		GameObject d = (GameObject) Instantiate(damage, transform.position, Quaternion.identity);
	}

}

Any advice guys?

You problem is not clear …

The position isn’t correct, right ?

You should add an empty point as a child of your player as an anchor point. Add a public Transform reference at the top of the script and drag & drop the anchor point from the inspector.

Then, you do as follow :

GameObject d = (GameObject) Instantiate(damage, transform.position, Quaternion.identity);
d.SetParent(anchorPoint);
d.transform.localPosition = Vector3.zero;