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 Lachee1 · Nov 18, 2010 at 11:03 AM · guibuttonwindowstoggle

GUI window help

may first gui window opens via a toggle switch. but inside that window i would like a button or a toggole to open another. I hve tryed to use button and toggle but they both wont work. Can someone please help?

here is a copy of my code:

var windowRect : Rect = Rect (20, 40, 127, 70); var windowRect2 : Rect = Rect (100,12, Screen.height , 70); var doMenu : boolean = false; var doFacer : boolean = false; var icon : Texture2D; var customSkin : GUISkin; var target : Transform; var place1 : Transform; var place2 : Transform; var place3 : Transform; var place4 : Transform; var place5 : Transform;

function OnGUI () { GUI.skin = customSkin; //menu button doMenu = GUI.Toggle (Rect (10,10,100,20), doMenu, "Menu");

if (doMenu){ windowRect2 = GUI.Window (1, windowRect2, DoMyWindow2, " "); } //Menu Button End

}

// Make the contents of the window function DoMyWindow (windowID : int) {

GUI.Label (Rect (6, 1, 2500, 20), "Object In Area"); if (GUI.Button (Rect (10,20,100,20), "Harvest")){ print ("Got a click"); target = place1; } if (GUI.Button (Rect (15,40,100,20), "-Moon Mounter")){ print ("Got a click"); target = place2; } GUI.DragWindow (Rect (0,0,10000,10000));

}

function DoMyWindow2 (windowID : int) {

GUI.Label (Rect (6, 1, 2500, 20), "Menu");

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

if (GUI.Button (Rect (15,40,100,20), "Facer")){ windowRect = GUI.Window (0, windowRect, DoMyWindow, ""); } }

function Update () { var targetPoint = target.position; var targetRotation = Quaternion.LookRotation (targetPoint - transform.position, Vector3.up); transform.rotation = Quaternion.Slerp(transform.rotation, targetRotation, Time.deltaTime * 2.0);

}

Thanks in advance, Lachee

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 Slem · Nov 18, 2010 at 11:36 AM

What you need to do is to add another bool that does the GUI.Window inside the OnGUI function just below the other one like this:

if (doMenu){
windowRect2 = GUI.Window (1, windowRect2, DoMyWindow2, " ");
if(doOtherWindow) { GUI.window(2, windowRectForSecondWindow, DoMyWindow); }
}
//inside DoMyWindow2 function
if (GUI.Button (Rect (15,40,100,20), "Facer")){
doOtherWindow = !doOtherWindow;
}

Hope this helps.

Comment
Add comment · Show 2 · 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 Bampf · Nov 18, 2010 at 02:17 PM 0
Share

To elaborate: the reason this is needed is because if (GUI.Button(...)) is only true once, then the button is first pressed. You need to store the fact that the 2nd window was invoked so that it gets drawn every time OnGUI is called.

avatar image Lachee1 · Nov 19, 2010 at 03:41 AM 0
Share

thank you for helping

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

Need help with toggle button 1 Answer

Whats wrong with my GUI.Toggle? 2 Answers

Is there a better way to access the single active Toggle in a ToggleGroup? 4 Answers

GUILayout Window Help 1 Answer

GUI window popup button 1 Answer


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