- Home /
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.
I'm not sure what your question is actually about.
Do you want round / circular buttons? That's only partially possible. All GUI elements are rectangular but you can use images with alpha to make them appear round. The input detection is still based on the enclosing rectangle.
Do you want to arrange multiple GUI elements / buttons in a circular manner lika a Piemenu? In this case it depends on what the elements look like and how big their content is. It's difficult to arrange arbitrary elements with variable length in a circular way.
You should edit your question and tell us what you actually want to do. Your whole description is just about your concerns that is should be in UnityScript and where you searched already for a solution but you missed to describe the most important thing: your question. Provide images of examples if possible.
A piemenu, runescapes $$anonymous$$imap, 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
Answer by robertbu · Nov 19, 2013 at 06:28 PM
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
Alternately you can move to use a GUITexture for the button and use an On$$anonymous$$ouseDown() or On$$anonymous$$ouseUp() script to process the click.
Your answer
Follow this Question
Related Questions
Setting Scroll View Width GUILayout 1 Answer
GUI GameObject Button? 1 Answer
Round Slider (Circle shaped slider GUI control) 1 Answer
How to activate a button? 1 Answer
Gui Text Script 4 Answers