Search Unity

Add a small text when you kill an enemy

Discussion in 'UGUI & TextMesh Pro' started by joni-giuro, Sep 16, 2015.

  1. joni-giuro

    joni-giuro

    Joined:
    Nov 21, 2013
    Posts:
    435
    Hi,
    this is more of a structural question then UI specifically. Let me explain:
    I have a couple of enemies in my game, when you kill one of them it plays a small animation and I'd like to have a small number appearing over his head with the amount of points you get for killing him. My question is:
    should the UI element containing the text be part of the enemy prefab and just show it when he gets killed or should it be a separate prefab and get instantiated there when he dies?
    I hope the question is clear, if not, just tell me and I'll explain better.

    Thanks

    Joni
     
  2. LeftyRighty

    LeftyRighty

    Joined:
    Nov 2, 2012
    Posts:
    5,148
    Can do it either way...

    are you only going to use this for the one thing? or can you do other things with the overhead indicator? if its just the one thing I'd probably go with instantiate when you need it.

    if you can reuse that "world canvas over their head" for other things, I'd probably make it a part of the prefab


    instantiate/destroy does have an overhead, but it might not cause any problems with your game if it doesn't happen alot at the same time... that's where the profiler comes in later on. Pick one, if it's causing problems, refactor for the other and see which is the "best".
     
  3. joni-giuro

    joni-giuro

    Joined:
    Nov 21, 2013
    Posts:
    435
    Thanks :) I will probably instantiate it and see how it affects the game, I might go back to it later. I'm just trying to figure out exactly how to do things as I don't want to pick up bad habits.