- Home /
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!
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... >_<
heal1items is a Texture2d. Im trying to buttons with textures on them.
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.
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.