Lazarus
Lazarus

Reputation: 427

Unity, How to set the sprite in front the background Image?

I had make a background image, and running an animation. The problem is the animation layer is behind the background image.

How to sort it?

Information (see the screenshot):

Background Image : z = 0 (Green Color on the picture), GUITexture

explosion : z = -5 (Yellow color on the picture), sprite Renderer

camera : z = -10


I had try Reverse the number, but it still same. I also try to add sprite component on the background image, but the sort layer look like still not working(maybe using wrong method).

Below is the screenshot.

enter image description here

Upvotes: 2

Views: 22673

Answers (2)

Antimatterr
Antimatterr

Reputation: 149

Click on the sprite you want on top of some background => go to Sprite Renderer under, Under sprite renderer there will be option of additional setting click on that and set "Order in Layer" property to any number less than 0 like -1, -10 or any negative number

you can see here in "order in layer" by default it's 0 set that to some negative value.

Upvotes: 0

limoragni
limoragni

Reputation: 2776

Just for reference

Well, the first thing you could an is common to do is to change the Z axis. If you are using a 2D orthogonal camera, that doesn't generate difference in the size of the sprites. If the distances are small you are going to experiment the so called Z fighting.

But the correct way to do it in this case would be to use the sorting layers and the Order in layer property. You can check this our too.

For this particular case

I assume that your are referring to an static background, that is always there, still. This two cameras approach is cool.

I don't know what kind of game are you doing, but an still background in most cases tend to be boring, and if you take advantage of the camera perspective you can get also a nice parallax effect by positioning the background on a different Z :)

A hack for Z fighting

I use this script for solving the Z fighting between textures. It overrides the render queue. Is hacky, but efficient. You just change the value and the higher values are rendered first!

using UnityEngine;
using System.Collections;

public class OverrideRenderQueue : MonoBehaviour {
    public int queueOrder = 3000;

    void Start ()
    {
        renderer.material.renderQueue = queueOrder;
    }
}

Upvotes: 2

Related Questions