0
\$\begingroup\$

Please refer the image below to understand.

I am working on 2D game. I have three elements: "background(layer 0), foreground(layer 1) and the object".

I have used sprite renderer to set background and foreground images. Object gets instantiated during runtime.

How do i make Part-A of the object invisible? I want to make object visible only on foreground. If the object is completely on the background, it should be completely invisible. if the object is completely on foreground, it should be completely visible. Part-A and Part-B are just for reference. It is one single object.

enter image description here

The goal to be achieved is the image below:

enter image description here

\$\endgroup\$
1
\$\begingroup\$

via editor or via script change sorting order in the SpriteRenderer as follows:

foreground: 0
your object: 1
background: 2

Via script you access this property by doing:

GetComponent<SpriteRenderer>().sortingOrder
\$\endgroup\$
  • \$\begingroup\$ This should be selected as right answer. \$\endgroup\$ – S. Tarık Çetin Nov 1 '15 at 21:37

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.