- Home /
How can i avoid mouse clicking on alpha areas in my GUITexture?
I have made a GUITexture and placed it in the middle of my screen. It is a picture of a ring. I want the picture to glow when I click on it BUT i want to avoid the pixels that are transparent (the middle and the four corners of the picture). I have tested the hitTest method and was wondering how i can access a single pixel of the GUITexture.
I know of no easy way to make this happen. What you need to do:
Have a read/write enable version of this texture. It can be the texture you use in the game, or if you can live with just a bit of imprecision, it can be a lower resolution version of the image.
You need to figure out the position of the mouse click on texture relative to the lower left corner. With a GUITexture, this can be complicated because you have 1) pixel inset values, 2) position in Viewport coordinates and 3) transform.localScale.
Using the relative position, get the pixel from the read/write enabled texture.
Hmmm i definitely took account for the pixel Inset and the position coordinates. Totally forgot about its localScale. But I believe scale shouldnt be a problem since i havent messed with it.
Answer by GoodArcade · Nov 06, 2014 at 06:27 PM
Ok i figured it out. I seem to have found the relative position of the texture but I was still getting weird results. Did some more research and changed GetPixel() to GetPixelBilinear(). Works wonderfully now! Thanks for the info!