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 HHameline · Apr 29, 2011 at 02:05 PM · guiopen

GUI.Window Not Appearing on button click

I have a scroll area of boxes with buttons and I would like to click on the view button and open a Gui.Window. The view button is registering the click, but is never getting into the openItemWindow() function and the GUI.Window isn't opening either. Any help would be appreciated.

void AutoItemLayout() { GUI.enabled = windowNotOpen; GUI.BeginGroup(new Rect(0, 0, SHOP_WIDTH, SHOP_HEIGHT)); GUI.Box(new Rect(0, 0, SHOP_WIDTH, SHOP_HEIGHT), "");

 category = GUI.Toolbar(new Rect(5, 5, SHOP_WIDTH - 10, 85), category, categoryName);              

 GUI.Box(new Rect(5, 95, (SHOP_WIDTH - 10), (SHOP_HEIGHT - 100)), "");
 scrollViewVector = GUI.BeginScrollView(new Rect(10, 100, (SHOP_WIDTH - 20), (SHOP_HEIGHT - 110)), scrollViewVector, new Rect(0, 0, 0, scrollHeight));

 if (category != currentCategory)
 {            
     switch (category)
     {
         case 0:
             displayItems = ShopManager.Instance.clothes;
             currentCategory = 0;                    
             break;
         case 1:
             displayItems = ShopManager.Instance.pencilPlayground;
             currentCategory = 1;                    
             break;
         case 2:
             displayItems = ShopManager.Instance.music;
             currentCategory = 2;                    
             break;
         case 3:
             displayItems = ShopManager.Instance.zopet;
             currentCategory = 3;                   
             break;
     }
     setUpShopLayout();            
 }       

 for (int i = 0; i < itemBoxPositions.Count; i++)
 {
     GUI.Box(itemBoxPositions[i],  displayItems[i]);
     GUI.Box(new Rect(5 + itemBoxPositions[i].x, 20 + itemBoxPositions[i].y, itemBoxPositions[i].width - 10, itemBoxPositions[i].height - 50), "");
     GUI.Label(new Rect(5 + itemBoxPositions[i].x, itemBoxPositions[i].height - 25 + itemBoxPositions[i].y, itemBoxPositions[i].width / 2 - 10, 20), "Price");
     if (GUI.Button(new Rect(itemBoxPositions[i].width / 2 + itemBoxPositions[i].x, itemBoxPositions[i].height - 25 + itemBoxPositions[i].y, itemBoxPositions[i].width / 2 - 10, 20), "View"))
     {
         Debug.Log("View " + i + " got clicked.");
         windowRect = GUI.Window(0, windowRect, openItemWindow, name);
     }           
 }

 GUI.EndScrollView();
 GUI.EndGroup();
 GUI.enabled = true;

}

public void openItemWindow(int id) { Debug.Log("In openItemWindow(" + id + ")"); if (GUI.Button(new Rect(windowRect.x + 5, windowRect.y - 25, 10, 20), "BUY")) { ShopManager.Instance.buyItem(currentCategory, displayItems[id]); Debug.Log(InventoryManager.Instance.playerInventory.Count); Debug.Log(InventoryManager.Instance.playgroundInventory.Count); itemBoxPositions.RemoveAt(itemBoxPositions.Count - 1); setUpShopLayout(); } }

Thanks, Hans Unity Newbie

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

2 Replies

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

Answer by HHameline · Apr 29, 2011 at 02:34 PM

I added a boolean variable (render) and in the OnGUI() function I added

if (render)
{
    openItemWindow(0);
}

then under the view button I put

if (GUI.Button(new Rect(itemBoxPositions[i].width / 2 + itemBoxPositions[i].x, itemBoxPositions[i].height - 25 + itemBoxPositions[i].y, itemBoxPositions[i].width / 2 - 10, 20), "View"))
 {           
     render = true;
 } 

I still need to tinker a little with it but for my immediate purposes that seems to be working.

public void openItemWindow(int id) { windowNotOpen = false; windowRect = GUI.Window(id, windowRect, itemWindow, displayItems[id]); }

public void itemWindow(int id) {
if(GUI.Button(new Rect(windowRect.width - 30, windowRect.y - 50, 30, 30), "X")) { render = false; } }

That's working perfectly now.

Thanks for the insight

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

Answer by Uzquiano · Apr 29, 2011 at 02:15 PM

Hi,

I always do it uisng GUILayout.Button(...) in your openItemWindow(). Is it a big issue for you to change that?

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 HHameline · Apr 29, 2011 at 02:31 PM 0
Share

That would cause quite a bit of grief actually. I did some tinkering and might have found a solution which I will post as an answer so I can properly display the code.

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

The name 'Joystick' does not denote a valid type ('not found') 2 Answers

Setting Scroll View Width GUILayout 1 Answer

Destroy a Game object on collision and add it to my Gui??? 1 Answer

PasswordField help. 1 Answer

Two Unity GUI questions 2 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