x


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 avariable', value' ormethod 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!

more ▼

asked Jul 13 '11 at 08:12 PM

PrezThompkins gravatar image

PrezThompkins
1 2 3 4

(comments are locked)
10|3000 characters needed characters left

2 answers: sort voted first

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... >_<

more ▼

answered Jul 13 '11 at 10:56 PM

SisterKy gravatar image

SisterKy
2.4k 33 41 59

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

Jul 13 '11 at 11:16 PM PrezThompkins

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

Jul 13 '11 at 11:23 PM SisterKy

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.

Jul 13 '11 at 11:49 PM PrezThompkins
(comments are locked)
10|3000 characters needed characters left

can you write down a full script for this?

more ▼

answered Nov 09 '12 at 08:55 AM

Timurov gravatar image

Timurov
37 3 8 15

(comments are locked)
10|3000 characters needed characters left
Your answer
toggle preview:

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

By Email:

Once you sign in you will be able to subscribe for any updates here

By RSS:

Answers

Answers and Comments

Topics:

x4150
x3680
x786
x224
x16

asked: Jul 13 '11 at 08:12 PM

Seen: 727 times

Last Updated: Nov 09 '12 at 08:55 AM