I’m developing 2d Tower Defense game and I want to be able to modify background texture(draw textures of dead units on it).
I don’t want to use separate objects to put on top of the background because I assume this will significantly slow down my game (number of units suppose to be VERY large).
I’ve found a code that allow to merge textures of the same size:
var tex1 : Texture2D;
var tex2 : Texture2D;
function Start (){
var pix1 = tex1.GetPixels32();
var pix2 = tex2.GetPixels32();
if (pix1.Length != pix2.Length) {
Debug.Log("Images need to be the same size");
return;
}
for (var i = 0; i < pix1.Length; i++) {
if (pix2*.a != 0) {*
pix1 = pix2*;*
}
}
tex1.SetPixels32(pix1);
tex1.Apply();
renderer.material.mainTexture = tex1;
}
How can I modify this code to be able to merge background texture with small textures (of dead units) at specific position?