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 FractalTree · May 15, 2012 at 03:04 AM · guiprefabbutton

GUI and buttons

Can i make a GUI by myself and put it into a prefab, so then i can spawn it? If yes, can it's sizes be adjustable to screen-size? And how can i check for button pressing not by giving GUI.Button(new rect(...)) coordinates of rectangle, but by asking for it's name in GUI prefab?

Comment
Add comment
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

3 Replies

· Add your reply
  • Sort: 
avatar image
0
Best Answer

Answer by Piflik · May 15, 2012 at 08:55 AM

'GUI.Button(new Rect(coordinates))' is the declaration of the button, so without it, you don't have one. You can try to store the button in a variable and use that in an if statement, but I have no idea, if that works (it should...).

 testButton = GUI.Button(new Rect(coordinates));
 
 if(testButton) {
     //do stuff
 }
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 FractalTree · May 15, 2012 at 08:58 AM 0
Share

No... Im talking not about putting "new Rect()" into variable. I've got a prefab with many daugther-buttons in it... How can i use if() asking it by it's name in prefab?

avatar image Piflik · May 15, 2012 at 09:16 AM 0
Share

You have to first give the button a name. The displayed label is just a string, it doesn't identify the button. Try what I said. If it works, it works, if not it should give you an error.

avatar image FractalTree · May 15, 2012 at 01:57 PM 0
Share

The thing u are trying to explain me is to make all the GUI by the script. Here is another thing: i've got READY GUI, contained into prefab. And this prefab has all the lables/textures/buttons and so on as daughter-objects... Each button has it own name into Inspector. By pressing key i place this prefab on the game scene. So can i use the name of button, given in prefab, into Inspector, to call for fucntion?

avatar image
0

Answer by KingCharizard · May 15, 2012 at 03:28 AM

Yes u can make a empty gameObject with a GUI script on it and make it a prefab. Yes the gui can be resized. About your last question I dont know what your asking but try looking at this for more info about working with the GUI

Comment
Add comment · Show 1 · 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 AlucardJay · May 15, 2012 at 04:53 AM 0
Share

to find and use scripts on other prefabs, try : http://unity3d.com/support/documentation/ScriptReference/GameObject.GetComponent.html

http://www.youtube.com/watch?v=jC3QO8QID80&feature=relmfu

and possibly : http://unity3d.com/support/documentation/ScriptReference/GameObject.Send$$anonymous$$essage.html

http://www.youtube.com/watch?v=4j-lh3C_w1Q&list=UUxvmZ5LIvbIZ7SVyGI6o6Xg∈dex=4&feature=plcp

avatar image
0

Answer by kolban · May 15, 2012 at 03:27 AM

Have a good read at the GUI Scripting Guide found here.

http://unity3d.com/support/documentation/Components/GUI%20Scripting%20Guide.html

The GUI is defined in Script and a Script is then attached to a GameObject and the OnGUI() method called on the Script to render the GUI. So ... with this in mind ... you can create a Script, attached that to a Game Object and then make a Prefab out of the Game Object. However, having achieved all of this, it still isn't cleat what it is you actually want to achieve.

Comment
Add comment · Show 1 · 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 FractalTree · May 15, 2012 at 07:25 AM 0
Share

I'm talking about the pressing the button. By googling i found the method: if(GUI.Button(new Rect(coordinates))){ } The GUI prefab, that i want to make, will contain many buttons. How can i remake this method to find press no by coordinates, but by it's name?

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

7 People are following this question.

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

Related Questions

GUI Creates a prefab? 1 Answer

How To Make GUI/Dragable Object - Att: Video 3 Answers

On Click paramaters disappear from button prefab? 5 Answers

Loading scene with a prefab GUI button? 1 Answer

Click on a button that is created post start. 0 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