Circle GUI Button, Javascript?

I’ve seen some around the forums written in C#, but I cant use that, since I cant modify it when I only know Javascript, and I have no idea where to go about it. Does anyone have any premade scripts, any asset store products that has this included or anyone that can tell me how to go about this in javascript? Thanks in advance.

A piemenu, runescapes minimap, runescapes run button. Stuff like that. Is there ANY way to do it in unity? Thanks in advance I mean a round button like the run button yes

1 Answer

1

There are a number of answers that deal with odd shaped buttons by looking at the underlying texture. But if you are dealing with circular buttons, you can just compare the mouse position to the Rect used to draw the button and only ‘fire’ the button code if the position is within a specified distance. For the example below, the Rect is 200 x 200, so any point within 100 pixels of the center will fire the button.

#pragma strict

var tex : Texture;
var rect = Rect(100,100,200,200);

function OnGUI() {
	if (GUI.Button(rect, tex)) {
		var dist = (rect.center - Event.current.mousePosition).magnitude;
		if (dist <= 100) {
			Debug.Log("Button Pressed");
		}
	} 
}

I dont understand most of that script, but I'll figure it out. Thank you!

Ah, this will still make it a square, I might aswell resize the actual button, right?

So @Bunney83 is correct. It is not the hit testing you are having an issue with but the look of the button? Not my area of expertise since I use EZGUI for UI, but you need to explore the use of GUISkins. See this answer: [http://answers.unity3d.com/questions/46158/how-to-create-a-transparent-button.html][1] Alternately you can move to use a GUITexture for the button and use an OnMouseDown() or OnMouseUp() script to process the click. [1]: http://answers.unity3d.com/questions/46158/how-to-create-a-transparent-button.html