Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 13 Next capture
2021 2022 2023
1 capture
13 Jun 22 - 13 Jun 22
sparklines
Close Help
  • 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 Conect11 · Sep 28, 2013 at 12:18 AM · arraysgui-text

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;
 }
Comment
Add comment · Show 10
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 tw1st3d · Sep 28, 2013 at 01:15 AM 0
Share

It doesn't look like any of this code has to do with what you're asking. Post what's making everything show up.

avatar image Conect11 · Sep 28, 2013 at 01:20 AM 0
Share

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);
 
 
 }
 
 
 }
avatar image tw1st3d · Sep 28, 2013 at 01:57 AM 0
Share

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.

avatar image Conect11 · Sep 28, 2013 at 02:02 AM 0
Share

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;
     }
      
     }
     }
     }
avatar image tw1st3d · Sep 28, 2013 at 02:07 AM 0
Share

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.

Show more comments

1 Reply

· Add your reply
  • Sort: 
avatar image
0
Best Answer

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.

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.

Follow this Question

Answers Answers and Comments

16 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

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


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