Tortoise41
Tortoise41

Reputation: 45

How do you place text above a parent in unity?

In my unity platformer game I have got an enemy with a simple patrolling script I would like to have text placed above him and it stays there. How could I go about doing this?

private void FixedUpdate()
{
    if(hit.collider != false)
    {
        if (isFacingRight)
        {
            rb.velocity = new Vector2(speed, rb.velocity.y);
            
        }
        else
        {

            
            rb.velocity = new Vector2(-speed, rb.velocity.y);
        }
    }
    else
    {
        isFacingRight = !isFacingRight;
        transform.localScale = new Vector3(-transform.localScale.x, 1f, 1f);
        m_Object.transform.localScale = new Vector3(-transform.localScale.x, 1f, 1f);
    }
}

Upvotes: 1

Views: 348

Answers (1)

turnipinrut
turnipinrut

Reputation: 614

Use the TextMeshPro package, and add a TextMesh as a child of the enemy, just above its head. This will keep the text over it

Upvotes: 1

Related Questions