Created
November 2, 2018 20:54
-
-
Save arkms/5c669b15f49815b186b50d7d9ab4720a to your computer and use it in GitHub Desktop.
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