I Have 2 types of Sprite Renderer GameObjects that user can spawn and place in world
- Window
- Block
- blocks are basic elements
- windows act as containers for blocks so user can group together similar blocks
how can i do such that blocks outside window appear below any window and blocks that are part of window (placed inside window) appear above that window.
I Have 2 types of Sprite Renderer GameObjects that user can spawn and place in world
- Window
- Block
- blocks are basic elements
- windows act as containers for blocks so user can group together similar blocks
how can i do such that blocks outside window appear below any window and blocks that are part of window (placed inside window) appear above that window.
Share Improve this question edited Mar 3 at 10:17 Jaimin Vashi asked Mar 3 at 10:11 Jaimin VashiJaimin Vashi 4311 bronze badges 5 |1 Answer
Reset to default -1To draw a block above glass if it is a child, set the sorting order property based on whether the glass is a parent of the block. For instance it could be something as simple as (and it goes without saying that this is pseudocode so don't use it):
var child = transform.GetChild(0);
if (child && child.CompareTag("block")){
GetComponent<SpriteRenderer>().sortingOrder = -1;
}
You would place such a script on all glass objects and ensure that all block objects are tagged with "block".
SpriteRenderer
or sprites onUI.Image
? – derHugo Commented Mar 3 at 10:16sortingOrder
and calculate and update them accordingly whenever the user modifies the window groupings – derHugo Commented Mar 3 at 10:47