Add: GetCircularTexture function

In this code, a circular crosshair texture is generated using a nested loop to iterate over each pixel of the texture. The distance between each pixel and the center of the texture is calculated using the Vector2.Distance function. If this distance is less than or equal to the radius of the circle, the pixel is set to white, otherwise it is set to transparent. The resulting texture is then drawn on the screen using the GUI.DrawTexture function.
This commit is contained in:
Jadis0x
2023-03-10 12:11:35 +03:00
committed by GitHub
parent 8793b6b6e2
commit c1c11265a5

View File

@@ -49,5 +49,28 @@ namespace DevourClient.Helpers
result.Apply(); result.Apply();
return result; return result;
} }
public static Texture2D GetCircularTexture(int width, int height)
{
Texture2D texture = new Texture2D(width, height);
for (int x = 0; x < texture.width; x++)
{
for (int y = 0; y < texture.height; y++)
{
if (Vector2.Distance(new Vector2(x, y), new Vector2(texture.width / 2, texture.height / 2)) <= texture.width / 2)
{
texture.SetPixel(x, y, Color.white);
}
else
{
texture.SetPixel(x, y, Color.clear);
}
}
}
texture.Apply();
return texture;
}
} }
} }