Search Unity

Sprite prefab with GUI text

Discussion in 'Immediate Mode GUI (IMGUI)' started by monsieurtasse, Aug 17, 2015.

  1. monsieurtasse

    monsieurtasse

    Joined:
    Feb 2, 2013
    Posts:
    12
    Hello and thank you having a look!

    I am making a game based on the 2D Roguelike tutorial ( https://unity3d.com/learn/tutorials/projects/2d-roguelike-tutorial ), so I have prefabs that are spawned randomly, and the movement is grid based.

    I would like to display a variable on a sprite (see attachment).
    I need to access the number display, and it should move with the sprite itself.

    I am a bit confused as it looks more complicated than I thought it would be.

    The way I was thinking of doing is:
    - Have a child GUI Text displaying the variable
    - Have the anchor point and the font size depending on the screen size so it scales corectly.

    Is that the best way?
    It really feels like it's not so I'm asking!
    Thanks a lot!
     

    Attached Files:

  2. monsieurtasse

    monsieurtasse

    Joined:
    Feb 2, 2013
    Posts:
    12
  3. TonyLi

    TonyLi

    Joined:
    Apr 10, 2012
    Posts:
    12,697
    You could add a Unity UI world space canvas to your sprite, and add a Text element to that canvas.