GUITexture with Sphere Collider

I have a GUITexture that I want to have it trigger its MouseDown event based not on touching the texture itself but instead a touch on a circle within the texture. The “touch” zone if you will is an actual circle that has a diameter 80% of the width of the texture (and centered in the textured), if it’s full width then thats too sensitive of a touch zone for this particular game.

So, I looked into maybe using a SphereCollider but maybe there is a simpler way and also how to integrate it’s trigger and events into something that is in the GUI in screen space coordinates. This will need to work on iOS and Android and web browser/unity (only browser/unity for testing etc).

I’m using the button script for Unity 3.x below which works great as is. Also, new to Unity but I’ve gone through the entire 3D Platformer tutorial, good stuff!

Thanks to the responese the following worked for me.

		var touchDist = pos - new Vector2(radius,radius);	
		if (touchDist.magnitude <= (radius))
		Debug.Log("HIT SUCCESS " + pos);

SphereCollider sounds like overkill. In that script you linked to, there is a HitTest function. I think you’d modify that to look within the radius you desire to ‘filter’ out the click. In other words, the ‘hot spot’ is a rectangle enclosing your circle, and if it’s hit, then look to see if it’s hit within the radius (excluding the corners).

You could compute it directly according to your mouse position, instead of using some pseudo-3D collider functionality of Unity. I don’t know the actual syntax, though, although I do know the functionality to accomplish the following is provided by Unity. Meaning, this is very raw pseudo-code, which nevertheless should point you in the right direction:

if(UnityFunctionThatDetectsWhetherTheGUITextureHasBeenPushed()){
    touchDistanceVector=MousePositionXY()-CenterOfGuiTexture();
    if(touchDistanceVector.sqrMagnitude<(0.8*WidthOfGuiTexture)*(0.8*WidthOfGuiTexture)){
        print("GUITexture hit within 80% width circle!");
    }
}