- Home /
Cut holes in sprite using other sprites
Hi, is there a way to achive something like this? I want to render one sprite and then cut holes in it using other sprites on the scene
I suspect you will want to use a stencil shader. https://docs.unity3d.com/$$anonymous$$anual/SL-Stencil.html
To my knowledge there is no direct easy way to achieve this, if you need the green sprite to become transparent. One solution could be to try using a mask and adding new sprites to cover up everything but the gaps.
Answer by jmgek · Jun 07, 2017 at 12:23 AM
If you don't want to write a shader you can use the system drawing library: https://msdn.microsoft.com/en-us/library/system.drawing.bitmap(v=vs.110).aspx
With this you can create a Bitmap that contains all your pixels. Then you can just get the bounds of your textures and remove with SetPixel();
//You can convert a png or a jpg to a bitmap.
string path = "./path/to/your_image.bmp";
Bitmap img = (Bitmap)Bitmap.FromFile(path);
//Some loop to get the bounds of your sprite lets say its one pixel
int x = 0;
int y = 0;
Color color = Color.White;
img.SetPixel(x, y, color);
img.Save(path);
Answer by JacksonHLBC · Aug 22, 2020 at 06:28 PM
This is an old question, but for those still looking, it can be solved using Unity's Sprite Mask component. To set this up, all you need is to set the "mask interaction" option to "visible outside mask" on the main sprite and then make sprite masks with the others.