- Home /
[SOLVED] Puzzled why one particular GUIText won't appear
EDIT 3: Praise God, it's solved! Line 59 was the offender: if(inventoryArray[2] > 0) {
Once I commented that out, and removed the closing bracket, it was all good in the hood.
EDIT 2: FASCINATING! I think I've figured out that GuiText5 is somehow "parented" to the "water" object in the array, rather than the "film," like it's supposed to be. (though that's not a perfect description. Let me put it this way: Array([2] is water, [3] is Apple Brew, and [4] is film. Each has a GuiText attached to it so that when the player picks the item up it's visible in the inventory. Everything up to [2] appears fine, but let's say I pick up film; it won't appear in the inventory until I pick up water, but then it appears. I haven't tried Apple Brew [3] yet, but am thinking the same thing will happen. Looking at my script, everything has its own function, so am puzzled where I'm going wrong.
EDIT: I think I understand WHAT's going on here, but have no idea at the moment how to fix it.
Essentially, each GUIText is waiting on the previous GUIText to become active. In other words, the way I have it set up now, GUIText3 will not become enabled unless GUIText2 is, and 2 won't until 1 is, etc. Clearly, it's in how I've written the script :( (human error) If anyone can point out what exactly I did wrong, you'll be my hero.
OP:
So, this one has me stumped.
My pause menu has an inventory script attached to it. When I pick up an item, a GUIText appears on the pause screen stating that I have it. EXCEPT for one item, the Film. No matter what, it never appears, or rather, never enables in the inspector. Every other one does. The pickup item script is working fine, as another gameobject relies on having the film, and it runs perfectly, but the GUIText simply never appears. I have it attached to the gameobject properly, and set up in the inspector right. I think the issue is in the script itself, but am not positive. Any help is humbly appreciated. The offending object is inventoryText5. God bless.
//inventory
static var inventoryArray : int[] = [1,0,0,0,0,0,0,0,0,0,0,0,0,0,0];
var inventoryText : GameObject;
var inventoryText2 : GameObject;
var inventoryText3 : GameObject;
var inventoryText4 : GameObject;
var inventoryText5 : GameObject;
var inventoryText5b : GameObject;
static var PrisonKey : int = 0;
static var TempleKey : int = 0;
static var HealthPotion : int = 1;
static var HardTack : int = 0;
static var Water : int = 0;
static var AppleBrew : int = 0;
static var FilmforCam : int = 0;
//inventoryText.guiText.text = "Health Potion " + "[" + inventoryArray[0] + "]" + "\n" + "Hard Tack " + "[" + inventoryArray[1] + "]" + "\n" + "Water " + "[" + inventoryArray[2] + "]" + "\n" + "Apple Brew " + "[" + inventoryArray[3] + "]" + "\n";
function Start () {
if(inventoryArray[0] < 1) {
inventoryText.guiText.enabled = false;
if(inventoryArray[1] < 1) {
inventoryText2.guiText.enabled = false;
if(inventoryArray[2] < 1) {
inventoryText3.guiText.enabled = false;
if(inventoryArray[3] < 1) {
inventoryText4.guiText.enabled = false;
if(inventoryArray[4] < 1) {
inventoryText5.guiText.enabled = false;
}
}
}
}
}
}
function Update () {
if(inventoryArray[0] > 0) {//THIS LINE**
inventoryText5b.guiText.enabled = true;
//inventoryText5b.guiText.text = "" + "[" + inventoryArray[0] + "]" + "\n";
//if(inventoryArray[0] > 0) {
//if(Input.GetButtonDown("Stuff"))
//healthPotion();
//}
if(inventoryArray[1] > 0)
{
inventoryText2.guiText.enabled = true;
inventoryText2.guiText.text = "Hard Tack " + "[" + inventoryArray[1] + "]" + "\n";
//if(inventoryArray[1] > 0) {
if(Input.GetButtonDown("Sword Slash"))
hardTack();
}
if(inventoryArray[2] > 0) {
inventoryText3.guiText.enabled = true;
inventoryText3.guiText.text = "Water " + "[" + inventoryArray[2] + "]" + "\n";
if(inventoryArray[2] > 0) {
if(Input.GetButtonDown("Jump"))
water();
}
if(inventoryArray[3] > 0) {
inventoryText4.guiText.enabled = true;
inventoryText4.guiText.text = "Apple Brew " + "[" + inventoryArray[3] + "]" + "\n";
//if(AppleBrew > 0) {
if(Input.GetButtonDown("Weapon Switch"))
appleBrew();
}
if(inventoryArray[4] > 0) {
inventoryText5.guiText.enabled = true;
inventoryText5.guiText.text = "Film " + "[" + inventoryArray[4] + "]" + "\n";
if(Input.GetButtonDown("Start"))
Film();
}
//}
//}
}
if(inventoryArray[5] > 0) {//THIS LINE**
inventoryText.guiText.enabled = true;
inventoryText.guiText.text = "Health Potion " + "[" + inventoryArray[0] + "]" + "\n";
//if(inventoryArray[0] > 0) {
if(Input.GetButtonDown("Stuff"))
healthPotion();
}
}
}
function healthPotion () {
//if(inventoryArray[0] > 0) {
Playerhealth.curHealth += 15;
inventoryArray[0] -=1;
HealthPotion -=1;
if(inventoryArray[5] == 0) {
inventoryText.guiText.enabled = false;
}
}
function hardTack () {
Playerhunger.curHunger -= 5;
inventoryArray[1] -=1;
HardTack -=1;
if(inventoryArray[1] == 0) {
inventoryText2.guiText.enabled = false;
}
}
function water () {
Playerthirst.curThirst -= 100;
inventoryArray[2] -=1;
Water -=1;
if(inventoryArray[2] == 0) {
inventoryText3.guiText.enabled = false;
}
}
function appleBrew () {
Playerthirst.curThirst -= 300;
Playerthirst.curHunger -= 200;
inventoryArray[3] -=1;
AppleBrew -=1;
if(inventoryArray[3] == 0) {
inventoryText4.guiText.enabled = false;
}
}
function Film () {
if(inventoryArray[4] == 0) {
inventoryText5.guiText.enabled = false;
}
}
Are you just adding GUIText to an existing object, and not creating a GUIText object?
that's correct. Just double checked and see that indeed the prior guitexts block this one. Once they're obtained, the last one appears. I must have lost my $$anonymous$$d, because upon going through my own posts I see that I've had this very same issue before, here and fixed the issue according to the answer on that post, but nothing has changed this time. Poor sainted fafase is probably shaking their head at my stupidity.
Your answer
Follow this Question
Related Questions
Appear after set number of seconds 2 Answers
Fix Blurry UI text? 10 Answers
How to show an array of custom objects in Inspector? 2 Answers
GameObject Array in Editor GUI 3 Answers