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 /
This post has been wikified, any user with enough reputation can edit it.
avatar image
0
Question by Eroosio · Mar 16, 2014 at 12:44 PM · guiinventoryvisibleshownot showing

GUI Rect not showing on play

Hi,

I am following two different tutorials in order to create an inventory for my 2D game. Both of them use GUI Rect -style approach but whenever I try to test them out but in both cases there is a problem. The GUI doesn't appear anywhere on the screen. I have tried attaching the script to player object, empty object and even GUIText object but the Rect just stays hidden. I have no idea why this happens. Any hints?

Here's one of the scripts I'm trying. It's attached to player.

using UnityEngine; using System.Collections; using System.Collections.Generic;

public class Inventory2 : MonoBehaviour {

 public List<ItemList2> Inventory;
 public ItemList2[] Pockets;
 Rect inventoryWindow = new Rect (0, 0, 400, 300);
 RaycastHit hit;
 Ray ray;
 
 void Awake () {
 
     Inventory = new List<ItemList2> ();

 }
 
 // Update is called once per frame
 void Update () {
 
     ray = Camera.main.ScreenPointToRay(Input.mousePosition);
     if(Input.GetButtonDown("Fire1"))
        {
         if (collider.Raycast(ray,out hit, 20))
         {
             print(hit.collider.gameObject);
         }
         }

 }


 void onGUI()
 {
     inventoryWindow = GUI.Window (0, inventoryWindow, DomyWindow, "Inventory");
 }

 void DomyWindow (int windowId)
 {
     GUI.DragWindow(new Rect (0, 0, 600, 200));
 }

}

Comment
Add comment · Show 4
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 thornekey · Mar 16, 2014 at 01:07 PM 0
Share

what tutorial are you following. curious.

avatar image Eroosio · Mar 16, 2014 at 01:30 PM 0
Share

https://www.youtube.com/watch?v=32vZP_F2GBg

and

https://www.youtube.com/watch?v=bEL00R_4R7k

avatar image Eroosio · Mar 16, 2014 at 01:40 PM 0
Share

The other I'm using is this. The toggle button isn't showing and the Rect stays hidden even if inventoryWindowToggle = true.

{

 public Rect inventoryWindow = new Rect (300, 100, 400, 300);
 public bool inventoryWindowToggle = false;

 static public Dictionary<int, string> inventoryNameDictionary = new Dictionary<int, string>
 {
     {0, string.Empty},
     {1, string.Empty},
     {2, string.Empty},
     {3, string.Empty},
     {4, string.Empty},
     {5, string.Empty},
     {6, string.Empty}
     
 };

 ItemClass1 ItemObject = new ItemClass1 ();

 //Likely don't need this one but jsut to be on the safe side...
 /*static public Texture2D keyicon;
 static public Texture2D bendicon;
 static public Texture2D levericon;*/

 // Update is called once per frame
 void Update () {
 
 }

 //The toggle button
 void onGUI () {
     inventoryWindowToggle = GUI.Toggle (new Rect (800, 50, 100, 50), inventoryWindowToggle, "Inventory");

     if (inventoryWindowToggle)
     {
         inventoryWindow = GUI.Window(0, inventoryWindow, InventoryWindow$$anonymous$$ethod, "Inventory");

     }
 }

 //The inventory screen
 void InventoryWindow$$anonymous$$ethod (int WindowId)
 {
     GUILayout.BeginArea (new Rect (5, 20, 100, 100)); 

     GUILayout.BeginHorizontal ();
     GUILayout.Button (inventoryNameDictionary[0], GUILayout.Height (20));
     GUILayout.Button (inventoryNameDictionary[1], GUILayout.Height (20));
     GUILayout.Button (inventoryNameDictionary[2], GUILayout.Height (20));
     GUILayout.Button (inventoryNameDictionary[3], GUILayout.Height (20));
     GUILayout.EndHorizontal ();

     GUILayout.BeginHorizontal ();
     GUILayout.Button ("Item 1", GUILayout.Height (20));
     GUILayout.Button ("Item 1", GUILayout.Height (20));
     GUILayout.Button ("Item 1", GUILayout.Height (20));
     GUILayout.Button ("Item 1", GUILayout.Height (20));
     GUILayout.EndHorizontal ();

     GUILayout.EndArea ();
 }
avatar image thornekey Eroosio · Mar 16, 2014 at 01:41 PM 0
Share

Please convert this to a comment. its not an answer. If you think it is an answer, close the thread as answered :)

you can add debugs to your code to see how far its getting

just add Debug.Log("were here, 1");

tell me how far it gets before it breaks. i think its the if (inventoryWindowToggle) bit. why not just put the GUI toggle line before it as the if statement ?

2 Replies

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

Answer by Bunny83 · Mar 16, 2014 at 01:40 PM

It's OnGUI not onGUI

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 Eroosio · Mar 16, 2014 at 01:45 PM 0
Share

Thanks, it turns out I'm an idiot after all.

avatar image
0

Answer by thornekey · Mar 16, 2014 at 01:08 PM

try making

 Rect inventoryWindow = new Rect (0, 0, 400, 300);


into

 private Rect inventoryWindow = new Rect (0, 0, 400, 300);
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 Eroosio · Mar 16, 2014 at 01:26 PM 0
Share

No effect...

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

22 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 avatar image avatar image avatar image avatar image

Related Questions

Mysterious crash involving an array 2 Answers

loop GUI Buttons doesn`t respond 0 Answers

Adding Item object to Inventory List 0 Answers

Is there any easy way to keep buttons inside of box? (c#) 1 Answer

Inventory Help 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