Color Picker coordinates are incorrect

Hi guys,

I`ve created a color picker. The idea is: you click on a color and the shirt of the player becomes that color.

It works but somehow, the coordinates of the mouse the color picker gets are wrong.

This is my code (Javascript):

    GUI.BeginGroup (Rect (Screen.width*0.07, 0, 424, Screen.height));
        
GUI.BeginGroup (Rect (16, 16+32, 376, Screen.height-128));

            
                //Background color
GUI.DrawTexture(Rect(28,104,312+8,96+16), Background);

//this button contains one image with several colors in it
if (GUI.RepeatButton(Rect(32, 112, 312, 96),ColorPicker))
{Mouse = Input.mousePosition;
ShirtColor    = ColorPicker.GetPixel(Mouse.x-16-32-Screen.width*0.07,Mouse.y-112-48-24);
ShirtMaterialGirl.color = ShirtColor;}

            
            GUI.EndGroup();

GUI.EndGroup();

Java != JavaScript

Now that that’s out of the way. GUI coordinates have their origin at the top left, while mouse coordinates have their origin at the bottom left. So besides the realistic chance that some other calculation is wrong, you’ll have to read the mouse like this:

Mouse = Input.mousePosition;
Mouse.y = Screen.height - Mouse.y;

Hi, thanks for your reply.
I`ve edited my mistake.

I think this wil lead me in the right direction. I`ve had a headache because of this.

I will try your solution in a few hours.

Your solution doesn`t work. It flips the colors of the image

Edit:

I`ve found it!

Mouse.y = Mouse.y - Screen.height;

//instead of

Mouse.y = Screen.height - Mouse.y;

Thank you!

I’d recommend tidying up the code you have in that case. Use some variables instead of all those values.