Answer the question
In order to leave comments, you need to log in
How to merge two textures into one and add them to the model?
I want to apply two transparent textures on one 3d model.
public static Texture2D CombineTexture(Texture2D background, Texture2D TodrawLogo)
{
int width = TodrawLogo.width;
int height = TodrawLogo.height;
int backWidth = background.width;
int backHeight = background.height;
// bottom right corner
int startX = backWidth - width;
int startY = backHeight - height;
// loop through texture
int y = 0;
while (y < backHeight) {
int x = 0;
while (x < backWidth) {
// set normal pixels
background.SetPixel(x,y,background.GetPixel(x,y));
// if we are at bottom right apply logo
//TODO also check alpha, if there is no alpha apply it!
if(x >= startX && y < backHeight- startY)
background.SetPixel(x,y,TodrawLogo.GetPixel(x-startX,y-startY));
++x;
}
++y;
}
background.Apply();
return background;
}
public GameObject TestObject;
public Texture2D Back1, Back2, NewTexture;
public Material NewMaterial;
//
public void RunTest()
{
TestObject = GameObject.Find("TestCart");
TestObject.GetComponent<Animator>().Play("Action");
Back1.LoadImage("Sprite/Back/1");
Back2.LoadImage("Sprite/Back/2");
NewTexture = CombineTexture(Back1,Back2);
NewMaterial.Albedo.Add(NewTexture);
TestObject.Materials = NewMaterial;
}
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question