Unity: Combine two textures in one, basic in TextureA copy TextureB
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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