- Home /
Make Gui Text only appear based on array
Happy Friday night, friends.
So I figure this has to do with OnGui, but my lack of knowledge holds me back again, and come hoping for guidance. I have a pretty nice inventory script. Only issue is that the gui text assigned to the array will always appear (in the pause menu, where it's set up) So right from the beginning the player will always know every item / weapon that exists in the game. So what I'd like to do is have the Gui Text for each item only appear once the player actually gets the item. I'm incredibly grateful, and hope to contribute to the community soon so that I'm not just continually asking questions without giving something back. God bless.
//inventory
static var inventoryArray : int[] = [0,0,0,0,0,0,0,0,0,0,0,0,0,0,0];
var inventoryText : GameObject;
function Update () {
inventoryText.guiText.text = "Health Potion " + "[" + inventoryArray[0] + "]" + "\n" + "Hard Tack " + "[" + inventoryArray[1] + "]" + "\n" + "Water " + "[" + inventoryArray[2] + "]" + "\n" + "Apple Brew " + "[" + inventoryArray[3] + "]" + "\n";
if(Input.GetButton("Stuff"))
if(inventoryArray[0] > 0) {
healthPotion();
}
if(Input.GetButton("Sword Slash"))
if(inventoryArray[1] > 0) {
hardTack();
}
}
//inventoryArray[0]++;
//inventoryArray[1] ++;
function healthPotion () {
Playerhealth.curHealth += 15;
inventoryArray[0] -=1;
}
function hardTack () {
Playerhunger.curHunger -= 5;
inventoryArray[1] -=1;
}
It doesn't look like any of this code has to do with what you're asking. Post what's making everything show up.
yeah, thought about that after posting, but had to run to the store. Here's an individual pick up item script:
function Update () {
}
function OnTriggerEnter (col : Collider) {
pickuphardtacktext = true;
if (col.gameObject.tag == "Player") {
Inventory.inventoryArray[1]++;
Destroy(this.gameObject);
}
}
You're asking how to make something show up based on your array, but you're not supplying the code that currently is making everything show up. Can't really help you without that.
tw1st3d, maybe I misunderstood. I was thinking you meant the codes that were responsible for adding the items to the array, and housing the array. Those are literally it, as it comes to GuiText. I also have this camera switch script, which is where my pause menu is based:
using UnityEngine;
using System.Collections;
public class $$anonymous$$enu : $$anonymous$$onoBehaviour {
public Camera camera1;
public Camera camera2;
bool camera1ActiveBool;
void Start () {
camera1.camera.active = true;
camera2.camera.active = false;
camera1ActiveBool = true;
}
void Update () {
//use whatever button you want to toggle
if(Input.GetButtonDown("Inventory")){
if (camera1ActiveBool == true)
{
camera1.camera.active = false;
camera2.camera.active = true;
camera1ActiveBool = false;
Time.timeScale = 0;
}
else if (camera1ActiveBool == false)
{
camera1.camera.active = true;
camera2.camera.active = false;
camera1ActiveBool = true;
Time.timeScale = 1;
}
}
}
}
Again, not quite what we need. Post your OnGUI() method, along with how you're handling printing your items while you're paused. We need to be able to see how you're displaying all of these things before we can add a conditional for them.
Answer by Conect11 · Oct 17, 2013 at 11:54 AM
Solved. Switched from the array to a series of static variables, and used an if statement at each variable for the GUItext.
Your answer
Follow this Question
Related Questions
String manipulation (splitting, concatenation, etc.) 1 Answer
Lists, Arrays and c# equivilent of js Array() 1 Answer
Random an Array to push to another Array 0 Answers
JavaScript 3 Arrays questions 1 Answer
Update Gui Text with Score 2 Answers