Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. We have updated the language to the Editor Terms based on feedback from our employees and community. Learn more.
    Dismiss Notice

Need help (Overlapping texts on prefabs)

Discussion in '2D' started by jigstot28, Jun 9, 2020.

  1. jigstot28

    jigstot28

    Joined:
    Sep 19, 2019
    Posts:
    3
    First of all, sorry for my bad English and I'm also a total newbie in unity.

    I have this problem with my 2d prefab. My spawner works well, the mobs are moving perfectly. My problem is when the time a prefab overlays each other, the text always overlaps the other prefab.

    I want to just fix the text on every prefab without overlapping each other.
    Please help.

    here is a screenshot
    https://i.imgur.com/TdRjozh.png
     
  2. Derekloffin

    Derekloffin

    Joined:
    Mar 14, 2018
    Posts:
    322
    I'm not sure what you're trying to do here. My guess is you want to change the sort order of your prefab so that it sorts behind instead of in front of the image? If so, I'm curious why you have the prefab text in the first place, but ignoring that, if your prefab it in the UI space, I don't think you can alter that. You can put it into world space and have it sort like any other object though. This is controlled by the canvas. If your prefab is already a game object in the world then you need to alter the sprite render's sorting layer and/or order in layer depending how you want to do it.
     
  3. jigstot28

    jigstot28

    Joined:
    Sep 19, 2019
    Posts:
    3
    Thanks for the answer, sorry I didn't mention what I'm making.

    I'm currently developing a educational shooting game, its just a 2d shooting game where the player shoots bullets on enemies to gain score but in my game you have a set of bullets (eg. mammal, fish, reptile bullets) and the enemy spawn carries texts (eg. dog, snake, shark).
    The player then need to fire bullets corresponding on what the enemy is carrying in order to gain score.
     
  4. Derekloffin

    Derekloffin

    Joined:
    Mar 14, 2018
    Posts:
    322
    Ah, okay, that makes sense. Yeah, knowing that. My guess from the picture is that you are using a UI canvas in the UI space to show the text parts, which is why it is always sorting in front, so yeah, you'd need to move that into world space instead.
     
  5. jigstot28

    jigstot28

    Joined:
    Sep 19, 2019
    Posts:
    3
    Thanks man, you're a life saver.
    I think I got it now