Quantcast
Channel: Answers by "andresp"
Viewing all articles
Browse latest Browse all 14

Answer by andresp

$
0
0
there is no need to use "magic numbers" and trial and error here if you use GetPixelBilinear function instead of GetPixel: if (GUI.RepeatButton(new Rect(beginX, beginY, dimX, dimY), colorSpectrumTexture, GUI.skin.GetStyle("ColorPickerStyle"))) { Vector2 pickpos = Event.current.mousePosition; Vector2 coords = new Vector2((pickpos.x - beginX) / dimX, -(pickpos.y - beginY) / dimY); Color color = colorSpectrum.GetPixelBilinear(coords.x, coords.y); } Note: Make sure your "ColorPickerStyle" has no padding, margin and border; has UpperLeft alignment; and dimX and dimY are proportional to the size of your texture, i.e. it fills the entire Rect - for some reason I think Unity can't correctly stretch a background image of a GUI controller, like a RepeatButton, even with StretchWidth and StretchHeight enabled).

Viewing all articles
Browse latest Browse all 14

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>