Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 13 Next capture
2021 2022 2023
1 capture
13 Jun 22 - 13 Jun 22
sparklines
Close Help
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
avatar image
0
Question by Madswint · Nov 19, 2013 at 06:06 PM · javascriptguicircleroundgui button

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.

Comment
Add comment · Show 2
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image Bunny83 · Nov 19, 2013 at 06:33 PM 0
Share

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.

avatar image Madswint · Nov 19, 2013 at 07:40 PM 0
Share

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

1 Reply

· Add your reply
  • Sort: 
avatar image
0

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");
         }
     } 
 }
Comment
Add comment · Show 3 · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image Madswint · Nov 19, 2013 at 07:35 PM 0
Share

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

avatar image Madswint · Nov 19, 2013 at 08:22 PM 0
Share

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

avatar image robertbu · Nov 19, 2013 at 08:55 PM 0
Share

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

Hint: You can notify a user about this post by typing @username

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this Question

Answers Answers and Comments

18 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

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


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges