Dynamical color change of mouse pointer

Hello Guys,
just one short question:

I already know how to pick a color from where the mouse points at (getpixel) but is it possible somehoe to make the white of my mouse pointer (I have made a custom one) turn into the color the mouse points at?

Hopefully someone has some ideas. :slight_smile: If someone posts code, please try to post it in c# if possible - but if it is only possible in java, thats also okay I guess :o

Regards
olop

You have two cubes for example and one is red, one is green - the mouse should get the color of the cube you point at?

How did you create your custom mouse?

I have a texture which consists of many different colored pixels, so I built a colorpicker via GetPixel and I thought it would be cool if the mouse shows the color of the pixel it is pointing at by changing its color to the same the pixel has.

Here’s the code for my custom mouse pointer - I only made the windows mouse disappear and inserted my own pointer as a texutre:

Screen.showCursor = false;
			GUI.DrawTexture(new Rect(Input.mousePosition.x, Screen.height - Input.mousePosition.y, cursorWidth, cursorHeight), cursorImage);
1 Like

As suggested by olop01 take one guiTexture same like mouse pointer and hide default one. You can also change whatever color you want of a you custom cursor.

Does Screen.showCursor = false; work for you? I my project sometimes it works, sometimes not and you see both.

With Unity 4, the native OS cursor API gets exposed: http://blogs.unity3d.com/2012/10/22/cursor-api/

Now you can push your textures to the hardware cursor.

Dear Posters, thank you for your posts! Sadly none of these were related to the problem or included a hint for a soultion. I would be happy if we can find a solution for this.

@ unityCoder: Please re-read the main post to understand the problem right. And I AM olop :wink:

@ Alex: Yes it works, but it doesn’t change the color to the color of the pixel :stuck_out_tongue:

@ dkozar: Cool!

Put: GUI.color = _currentColor;
… just before the GUI.DrawTexture line. This will tint your texture. Full snippet:

_oldColor = GUI.color;
GUI.color = _currentColor;
GUI.DrawTexture(new Rect(Input.mousePosition.x, Screen.height - Input.mousePosition.y, cursorWidth, cursorHeight), cursorImage);
GUI.color = _oldColor; // reset back to old color

More info

So simple - but yet so awesome! Thank you very much sir! :smile: :smile: :smile:

NP! (instead of thanking me, retweet) :slight_smile: