Format
typescript
Texture2D.GetPixel(x, y, mipLevel)class: Texture2D
Description
Get the color of a specific pixel on a texture.
It can be used to read the color information of a specific pixel in a texture, allowing you to retrieve the pixel data of the texture at runtime.
Parameters
| param_name | type | description |
|---|---|---|
| x | number | The x coordinate of the pixel to retrieve, starting from 0. |
| y | number | The y coordinate of the pixel to retrieve, starting from 0. |
| mipLevel | number | The mip level of the texture. |
Return
| type | description |
|---|---|
Color | The color of the pixel. |
Code Example
typescript
let uuid = "31A9092E126B4B19BBFD9D5FCD75AA49";
let tex = Resources.Load<Texture2D>(Texture2D, uuid);
if (tex == null) {
throw new Exception("failed to load texture2d: " + uuid);
}
let color = tex.GetPixel(0, 0, 0);
Debug.Log("Pixel color at (0,0) is: ", color);