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 MikezNesh · Jun 27, 2010 at 01:03 AM · featuresgui-windowwindowrect

Adding different features to different GUI Windows...

I currently have 2 GUI Windows. I want to make one have a label and the other have a button.

Here is the script I'm using:(found off a tutorial)

var windowRect0 = Rect (20, 20, 120, 50);

var windowRect1 = Rect (20, 100, 120, 50);

function OnGUI () {

// Register the window. We create two windows that use the same function

// Notice that their IDs differ

windowRect0 = GUI.Window (0, windowRect0, DoMyWindow, "My Window");

windowRect1 = GUI.Window (1, windowRect1, DoMyWindow, "My Window");

}

// Make the contents of the window

function DoMyWindow (windowID : int) {

if (GUI.Button (Rect (10,20,100,20), "Hello World"))

print ("Got a click in window " + windowID);

// Make the windows be draggable.

GUI.DragWindow (Rect (0,0,10000,10000));

}

I don't really understand how to make a different window take a different part....

So how could I make my windowRect0 get the button and the windowRect1 get a label???

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

1 Reply

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

Answer by Mike 3 · Jun 27, 2010 at 01:14 AM

You'd either make two seperate DoMyWindow functions (So you'd call one from each Window function), or use a switch/if in the DoMyWindow function which decides what stuff to draw inside it

Edit (using the id to change behaviour):

in your DoMyWindow function:

switch(windowId) { case 0: //these case values would be better as defined variables so they can be changed //do something break;

 case 1:
     //do something
 break;

}

Comment
Add comment · Show 10 · 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 MikezNesh · Jun 27, 2010 at 09:14 AM 0
Share

How would I do the switch version? What would I put in the cases? Can you show me? Thanks.

avatar image MikezNesh · Jun 27, 2010 at 12:58 PM 0
Share

How would I get ahold of a window?

avatar image Mike 3 · Jun 27, 2010 at 01:24 PM 0
Share

Not sure I follow. the thing you're switching on is the variable passed to your function, and that's passed via the GUI.Window's first parameter. you just need to make sure you match up that parameter to the case

avatar image MikezNesh · Jun 27, 2010 at 01:32 PM 0
Share

??? So how would I do it? Could you do one example code in a case so I know what to do? Thanks.

avatar image Mike 3 · Jun 27, 2010 at 05:28 PM 0
Share

That's what the code already does - that code will work if you copy/paste it in (put the button code in //do something for case 0, label where //do something for case 1 is)

Show more comments

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

No one has followed this question yet.

Related Questions

Apply Render Texture To GUI + Transparency? 2 Answers

I'm looking for a script allowing Unity to receive information about a music (bpm, frequency, width,...) via OSC. Can anyone refer me? 0 Answers

Suggestion: Select "scripted importer" for different file types 0 Answers

How do I make a GUI display inside a Plane GameObject? 1 Answer

When will draw mode be available in 2d sprite renderer 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