Search Unity

  1. Megacity Metro Demo now available. Download now.
    Dismiss Notice
  2. Unity support for visionOS is now available. Learn more in our blog post.
    Dismiss Notice

Help with attaching a Text Object to a Prefab

Discussion in '2D' started by FeederGeorge, Apr 6, 2015.

  1. FeederGeorge

    FeederGeorge

    Joined:
    Nov 3, 2014
    Posts:
    1
    Hi, I'm new to making games with Unity, so I'm not even sure if what I am trying to do is feasible, but I am trying to make a card game, and I'm trying to make prefabs for each card. The cards are simply poorly made sprites with boxes where I was planning on putting descriptions of the cards (such as the card's name and health/attack stats). Instead of making the text on the sprites, I was hoping to attach text object components on a World Space canvas onto the imported sprites, and then storing prefabs of the sprites with text object and canvas components. The reason I am doing this is because I want the displayed text to be able to change, since my cards will be losing health and stuff, so I wanted the text to change dynamically, like how the cards in Hearthstone have attack and defense stats that change. So, the question I am asking is: is this viable? If so, how can I do this? I've tried doing it, but when I make the font size really small, the text gets extremely blurry, and I can't get legible font to fit onto my card prefabs without making my cards obscenely large, and I can't seem to scale the font down. If this implementation doesn't work, can someone tell me what else I could do to accomplish the same effect? Since Hearthstone is able to do something similar with its cards, I know it must be possible, I just don't know how they implemented it. Any help would be much appreciated, thanks!

    Edit: One thing I just tried that kind of works but seems extremely sloppy is I scaled my card sprite to an extremely large size, then I significantly increased the camera's field of view. This solution seems kind of hacky, but it achieves the effect I want. Are there any potential problems with doing it like this? if not, I will continue with this implementation. One last question though: I can see the text in my project, but when I entire Play Mode, the text disappears. Anyone know why this might be?
     
    Last edited: Apr 6, 2015
  2. PGJ

    PGJ

    Joined:
    Jan 21, 2014
    Posts:
    899
    What you want to do is quite viable...

    Have you tried adjusting the Canvas Scaler's Dynamic Pixel Per Unit value? Try increasing it to 100 or more.