• 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 PrezThompkins · Jul 13, 2011 at 08:12 PM · c#guibuttoninventorycs0119

GUI.Button is acting funky.

Hey guy's, I'm still working on that Inventory stuff! My issue today, is with GUI.Button. Iv scavenged around online, and have tried to CopyPasta example code, and even that doesn't work!

So, What I'm trying to do is when the game pauses, I have a series of buttons that pop up. Those button's are created by reading the player's inventory value, and returning buttons. The problem is, the GUI.Button command always returns errors. (error CS0119: Expression denotes a type', where a variable', value' or method group' was expected.)

Here's some code clips, to help bring the problem to light...

 public class PauseMenuScript : MonoBehaviour
 {
    
     public GUISkin skin;
     private float startTime = 0.1f;
     public Texture2D heal1Texture;
     
     private float savedTimeScale;
    
    
     public GameObject start;
     
    
     public enum Page { Playing, Inventory}
    
     private Page currentPage;
    .........
 
     void OnGUI () {
         if (skin != null) 
         {
             GUI.skin = skin;
             //GUI.Label(rect(0,0,100, 50), texture1);
         }
         
         if (IsGamePaused()) 
         {
             GUI.color = new Color(0,0,0);
             switch (currentPage) 
             {
                 case Page.Inventory: 
                 InventoryMenu(); 
                 InventoryScreen();
                 ShowBackButton();
                 break;
             }
         }   
     }
 
     void InventoryMenu()
     {
         BeginPage(400,200);
 
 
         if (GUILayout.Button (IsBeginning() ? "Play" : "Continue"))
             {
             UnPauseGame();
             }
         EndPage();
     }
     
     void InventoryScreen()
     {
         
         for (int i = 0; i < GetComponent<ThePlayerInventory>().heal1items; i++)
         {
             GUI.Button(Rect(400,400,450,450), heal1items);
         }
     }




Everything works fine until it's time to create a button. This did not work, even before I threw in the For Statement, I was just trying to find another work around before I asked. Any help is appreciated guys! Thanks!

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

Answer by SisterKy · Jul 13, 2011 at 10:56 PM

of what type is the variable heal1items? I think you are feeding an int in the Button where it expects a String?

Maybe try GUI.Button(Rect(...), heal1items.ToString());

Greetz, Ky.

Edit: Sorry, just saw that the typing is right there in the script -.-' d'oh...

Edit2: No, wait. heal1Texture is declared in the script, heal1items isn't... oO dear lord, I better go to bed... sorry I'm no help... >_<

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 PrezThompkins · Jul 13, 2011 at 11:16 PM 0
Share

heal1items is a Texture2d. Im trying to buttons with textures on them.

avatar image SisterKy · Jul 13, 2011 at 11:23 PM 0
Share

Hmm... two thoughts... 1. I think it should be Texture ins$$anonymous$$d of Texture2D for a GUI-Texture (?), 2. how do you compare i : int with a Texture2D in your for-loop? Greetz, $$anonymous$$y.

avatar image PrezThompkins · Jul 13, 2011 at 11:49 PM 0
Share

The for loop is something I just threw in there, it doesn't work outside of the loop iether. Iv switched it back to just Texture, issue still comes up. I'm thinking I'v missed something that should be obvious.

avatar image
0

Answer by Timurov · Nov 09, 2012 at 08:55 AM

can you write down a full script for this?

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

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.

Welcome to Unity Answers

The best place to ask and answer questions about development with Unity.

To help users navigate the site we have posted a site navigation guide.

If you are a new user to Unity Answers, check out our FAQ for more information.

Make sure to check out our Knowledge Base for commonly asked Unity questions.

If you are a moderator, see our Moderator Guidelines page.

We are making improvements to UA, see the list of changes.



Follow this Question

Answers Answers and Comments

4 People are following this question.

avatar image avatar image avatar image avatar image

Related Questions

Key for GUI.Button 2 Answers

Setting tooltip text depending on condition 1 Answer

C# Random Number on GUIButton click without updating every frame 0 Answers

C# GUI.Button highlighting and pressed effect 0 Answers

proper inventory system issue.. 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