Skip to content

Instantly share code, notes, and snippets.

@arkms
Created November 2, 2018 20:54
Show Gist options
  • Save arkms/5c669b15f49815b186b50d7d9ab4720a to your computer and use it in GitHub Desktop.
Save arkms/5c669b15f49815b186b50d7d9ab4720a to your computer and use it in GitHub Desktop.
Unity: Combine two textures in one, basic in TextureA copy TextureB
Texture2D CombineTexutes(Texture2D _textureA, Texture2D _textureB)
{
//Create new textures
Texture2D textureResult = new Texture2D(_textureA.width, _textureA.height);
//create clone form texture
textureResult.SetPixels(_textureA.GetPixels());
//Now copy texture B in texutre A
for (int x = 0; x<_textureB.width; x++)
{
for (int y = 0; y<_textureB.height; y++)
{
Color c = _textureB.GetPixel(x, y);
if (c.a > 0.0f) //Is not transparent
{
//Copy pixel colot in TexturaA
textureResult.SetPixel(x, y, c);
}
}
}
//Apply colors
textureResult.Apply();
return textureResult;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment