Type UnityEngine.Texture2D' does not contain a definition for 'alphaIsTransparency' - Works in editor, can't build other versions

The following code compiles in Visual Studio, and runs fine in the editor:

Texture2D texture = new Texture2D(1, 1);
texture.alphaIsTransparency = true;

but when I attempt to build either the standalone PC or the web version, I get the following error:

error CS1061: Type UnityEngine.Texture2D' does not contain a definition for alphaIsTransparency’ and no extension method alphaIsTransparency' of type UnityEngine.Texture2D’ could be found (are you missing a using directive or an assembly reference?)

If I remove the alphaIsTransparency line, I can build those versions just fine.

What would cause this error and how might I correct it?

I had the same trouble

Solution don’t use alphaIsTransparency, use TextureFormat.Alpha8


float ancho = 100, altoLista = 100;

use var texture = new Texture2D(ancho, altoLista, TextureFormat.Alpha8, true);

var c = new Color(29F / 255, 46F / 255, 73F / 255, 0.8F);
for(var i = 0; i < ancho; i++)
for(var j = 0; j < altoLista; j++)
texture.SetPixel(i, j, c);