Hovering text above enemies 2D
Context: 2D Sidescroller with some story elements
I am trying to make "floating/hovering" text boxes above enemies so players don't have to look at dialogue boxes whenever I am trying to include some context to the game story. I am not sure what the exact terminology is for this is and I have been having a difficult time looking for something that is relevant enough to what I'm going for.
An example of what I am trying to achieve is here in the Corgi Engine asset:
Do you already have on-screen textboxes implemented in your project, or are those needed as well?
I have on-screen dialogue textboxes yes. For now, whenever the player runs into some trigger collider it just triggers the dialogue box to read through. There should be a way to repurpose it above enemies and have it just cycle through a script of text.
Answer by oStaiko · Nov 03, 2016 at 10:58 PM
Here's part of a script I used to make a healthbar float over objects. The script itself went on a prefab of a healthbar, which would be spawned and attached to every single game object that had health, something like this:
hp = Instantiate(hpPrefab);
hp.parentObject = gameObject;
public float xDisp; //x offset from center of parent
public float yDisp;
public GameObject parentObject; //Reference to attached object
void Update()
{
Vector3 wantedPos = Camera.main.WorldToViewportPoint(parentObject.transform.position);
transform.position = new Vector3(wantedPos.x*Screen.width + xDisp,wantedPos.y*Screen.height + yDisp,40);
}
Your answer
![](https://koobas.hobune.stream/wayback/20220612100003im_/https://answers.unity.com/themes/thub/images/avi.jpg)
Follow this Question
Related Questions
Text Mesh pro won't show certain characters 1 Answer
UI Text Editing Problem, What's Wrong? Need Anybody to Assist 1 Answer
Tooltip doesn't work 0 Answers
Tooltip on hovering certains words in textbox. 0 Answers
How to lock the camera on Y axis? 0 Answers