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

prospective in unity 2d

Discussion in '2D' started by sirjacobgoodrich, Sep 26, 2019.

  1. sirjacobgoodrich

    sirjacobgoodrich

    Joined:
    Jul 27, 2019
    Posts:
    12
    I'm making a 2d rts, and i'm trying to make it so that it appears that units can go in-front of and behind objects



    like this

    l what I have.PNG what i want.PNG
     
    Luto_Akino likes this.
  2. Helladah

    Helladah

    Joined:
    May 5, 2018
    Posts:
    254
    You have to use the shorting layer at the inspector at the SpriteRenderer side
     
  3. sirjacobgoodrich

    sirjacobgoodrich

    Joined:
    Jul 27, 2019
    Posts:
    12
    I know,i want it appear that it is behind the tower when, when from the player's prospective it would be and be infront of it when from the player's prospective it would be.
     
  4. Deleted User

    Deleted User

    Guest

    Code (CSharp):
    1. if (player.transform.position.y < transform.position.y)
    2.         {
    3.             sprite.sortingOrder = player.GetComponent<SpriteRenderer>().sortingOrder - 1;
    4.         }
    5.         else
    6.         {
    7.             sprite.sortingOrder = player.GetComponent<SpriteRenderer>().sortingOrder + 1;
    8.         }
    sprite is the sprite render and player the player gameObject
    Put this in the update funktion it will work for objects that are not part of the tilemap.

    If someone find a way how to do this with tiles please leave a replay at my thread.
    https://forum.unity.com/threads/tilemap-walk-behind-tiles.750725/
     
    Luto_Akino likes this.
  5. Luto_Akino

    Luto_Akino

    Joined:
    Feb 20, 2018
    Posts:
    21
    you have some video of your game?
     
  6. sirjacobgoodrich

    sirjacobgoodrich

    Joined:
    Jul 27, 2019
    Posts:
    12
    thx m8
     
  7. coidevoid

    coidevoid

    Joined:
    Oct 26, 2017
    Posts:
    55
    Well if your castle is static, it's better to update the sorting order of your player and assign the castle sorting order at start depending of its Y position