Struggling to find how to access the Texture 2D of a sprite.

Hiya, I’ve been trying to find out how to access the Texture2D of a sprite so I can use Texture2D.GetPixel to check for transparency of the pixel I click on. So far I’ve hit a lot of dead ends, anyone know the answer?

Thanks very much!

Romano

I was doing this recently and I found it pretty straight forward:

Color myPixel = GetComponent<SpriteRenderer>().sprite.texture.GetPixel(x,y);

What you receive is of the type Color. You can also use GetPixels and get a block of the texture.

Make sure you are calculating correctly the position of the click and the pixel you want to check.

Good luck :slight_smile: