- Home /
Sprite Layers
When working with sprites in the same layer, I noticed that the sprites/GameObjects that are created first are automatically on a higher layer than those created after them.
Is there any way to change this behavior to make the last GameObject created the highest in its layer?
Answer by Lazdude17 · Jul 29, 2014 at 04:18 PM
Don't think of it so much as when the object is created but when it's layer is assigned. I believe setting the layer in the start function for the specific sprites you want should solve the problem.
This sounds like it'll work better! I wanted to avoid the Z-axis if I could. Thanks!
I'm doing it this way in my game to make weapon particles appear in front of my weapons ins$$anonymous$$d of behind.
void Start ()
{
particleSystem.renderer.sortingLayerName = "Player";
particleSystem.renderer.sortingOrder = 5;
}
You can also use the sprite renderer component of an object too.
Wait, wait, wait. Are sprites first ordered by LayerName, THEN by sortingOrder?
They ARE! $$anonymous$$uahahaha! This fixes everything, Thanks!
Answer by feyyd · Jul 29, 2014 at 04:31 PM
Perhaps it isn't what you are looking for, but when the sprites are created you can set the sortingOrder and sortingLayer programatically with sprite.sortingOrder and sprite.sortingLayerName.
Your answer
Follow this Question
Related Questions
2D Platformer: Area under platform hiding player 2 Answers
using Contains(gameObject) to find and destroy a gameObject from a list 2 Answers
PLayer animation 0 Answers
Make 2D sprites adjust layers based on distance in a 3D World 0 Answers
How to achieve this basic physics effect? Detect when to change layers 2 Answers