- Home /
How to make the pixels of an object that are obscured by a specific object transparent Unity2D
Hello, I was wondering how to make pixels that are obscured by an object transparent. I guess that a less vague way of putting this is making a "Hole" object that creates a transparent "Hole" in the object underneath it. I've made a few example images to further clarify
So for instance, in the picture above if I have 3 objects:
Object 1, the Hole, and Object 3
with the hole resting on top of Object 1 how could I achieve something like the picture below> I feel like the correct way of doing this would be through shaders, but I am completely unexpirenced with shaders and have no clue where to start, espically since the documentation I looked through seemed to all be for 3D, and the answer I found for 2D shaders seemed too advanced to pick apart without experience.
Answer by Twistorian · Sep 21, 2017 at 12:24 AM
You can do this using Sprite Masks.
So, add Mask Interaction to one object and add a mask, that shows the effect.
In your example, add a Mask Interaction to the large square, like in the picture below. Mask Interaction is the last item on the SpriteRenderer. For this effect, pick "Visible Outside Mask". Now it will be drawn unless a mask covers it.
Second, add a Sprite Mask ("The hole"). It needs to have a sprite of its own to show any effect. Put it in the middle of the large square.
Third, to complete your example, add another, smaller sprite square (without mask interaction) in the middle of the picture.
Observe greatness and think of everything you could achieve with this.
Your answer
Follow this Question
Related Questions
Unity 5.6 Creating a Distortion in Sprites? 1 Answer
Limit Amount of Light Applied to Sprite 0 Answers
Hiding a sprite partially (shader? masking?) 0 Answers
Alpha masks on sprites? 0 Answers
Sprites not working with Depth of Field Post Processing 0 Answers