Help - function GetPixel in VR

Hello,

I’am testing VR (3D) and new to unity.

I want to get color from image (like color picker).

Function GetPixel working well for me, but in another direction or rotation returns bad COLOR.
Only when camera is forward to image, solution works well.

Why? Can you help me please?

Thank you.

My code is

Color color = image.sprite.texture.GetPixel(
(int)((pickerObj.transform.position.x - transform.position.x) * (1 / GetComponent<RectTransform>().localScale.x) * (1 / GetComponentInParent<Canvas>().scaleFactor)),
(int)((pickerObj.transform.position.y - transform.position.y) * (1 / GetComponent<RectTransform>().localScale.y) * (1 / GetComponentInParent<Canvas>().scaleFactor)) + GetComponent<Image>().sprite.texture.height)
);

What is the bad color?

1 Like

Hi, I resolved this issue today.

Bad color was → I pick red color → return was black.

I fix this with set canvas to width and height 1 and set scale.

Calculate position

var posx = pickerObj.transform.localPosition.x * 256; // image width
var posy = pickerObj.transform.localPosition.y * 256 + 256; // image heght

Thanks.