I want button to activate only when pointer is over green part of image and ignore transparent part in lower right corner.
I looked up and found this guy with same problem here, so I tried using “Image.alphaHitTestMinimumThreshold” (which sounds like perfect solution for my problem) but it seems that it no longer works (‘Image’ does not contain a definition for it).
So… how do I do it?
You could get the localRect coordinate and change that to a percentage and use the percentage to get the pixel color in the texture. Just make sure the texture is read/write enabled. The code below will do it… I think… might need to play with the x and y positions a little. And definitely will need to set the pivot point to the bottom left corner (0,0).
public RectTransform but;
public Texture2D tex;
public void OnButtonPressed()
{
Vector2 pos = new Vector2();
Vector2 mouse = EventSystem.current.currentInputModule.input.mousePosition;
RectTransformUtility.ScreenPointToLocalPointInRectangle(but,mouse , null, out pos);
float px = pos.x / but.rect.width;
float py = pos.y / but.rect.height;
float tx = px * tex.width;
float ty = py * tex.height;
Color col = tex.GetPixel((int)tx, (int)ty);
}