- Home /
Transparent part of wall with door(2d)
I have diffrent sprites of doors and walls:
There is a way to make the area(with ? in picture) transparent, to see what is behind the wall?
Answer by robertbu · Oct 06, 2014 at 08:17 PM
What you have now is a design question as much as a specific technical question. As with many things in Unity, there are multiple ways of doing things, none are simple (or at least as simple as you want them to be). And with such limited information about your app, I cannot even direct you to a 'best' solution. Here is a list:
You can use a specialized shader that cuts out a part of the texture. I don't know of a free, pre-built one that cuts rectangles, but here is blog post for a circle: http://unitycoder.com/blog/2012/02/22/x-ray-cutout-shader-with-mouse/
You can use a texture atlas, and map a door onto one side of your cube. Here is an link to get you started with UV mapping the sides of a cube: http://answers.unity3d.com/questions/542787/change-texture-of-cube-sides.html
If you always only see one side of the wall, you can apply, scale, and offset a texture with a cutout to the object.
If your underlying mesh identifies the area of the door (i.e. the vertices match the door opening, the triangles that form the quad that is the door don't share vertices, and you can identify the right vertices), then you have three other choices:
Use a shader that supports vertex color and set the color to transparent for the vertices that form the door.
UV map a transparent texture onto the vertices/triangles that form the door.
Remove the triangles from the mesh that form the door
Though the operation is slow, you can dynamically change the pixels in a rectangular area to transparent in the texture used on the door. This will only work if you only see one side of the wall, or if you UV map a portion of the texture to the correct side of the wall.
You can use a shader that supports a mask, and then either construct or pick a mask to turn the right area transparent.
And I'm sure this is not a complete list.