How to color 2D sprite for android? I don’t know, why my script does not fill my sprite with red. I seem to be doing everything following the documentation.
using UnityEngine;
public class Test : MonoBehaviour
{
[SerializeField] private Texture2D _texture;
// Start is called before the first frame update
void Start()
{
_texture = new Texture2D(128, 128);
this.GetComponent<Renderer>().material.mainTexture = _texture;
for (int y = 0; y < 128; y++)
{
for (int x = 0; x < 128; x++)
{
_texture.SetPixel(x, y, Color.red);
}
}
_texture.Apply();
}
}
I don’t work with textures, so I won’t be of much help with that; however, I’m pretty sure simply changing the Sprite Renderer color will work on android.
This should work: GetComponent<SpriteRenderer>().color = Color.red;
So after doing some research and tests, I’m fairly certain that Texture2D isn’t actually intended to be used with 2D. It’s called that because it’s literally 2-dimensional, but it’s for 3D objects.
Putting your script on a cube or plane will make them red, but no texture affects sprites at all - likely because sprites are a kind of texture themselves.
This doesn’t mean that what you want to accomplish is impossible, but you’ll probably have to create a custom shader for it.
It would seem that such a simple task, but such a complex solution. I will wait for other answers, maybe there is a simple solution to the problem. Thank you for your help!