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 Silvio · Jul 17, 2010 at 11:38 PM · guiinventoryplacementcoinscollection

Game Logic - How to Check if player has enough Coins before Instanstiating a House?

Okay - Currently, a Player runs around, and collects Coins, timber, etc... Its populated on a GUI (sort of like an Inventory system) It places each object (which are stack able) into the Inventory box.

What i want to do, is when the player goes to another GUI area, to say - Build House, or Plant Tree, - The Game checks to see if it has X available Coins. If not, it flashes a. YOU CANT DO THAT. if it does, then it allows me to Spawn a Prefab to the location of the players choice.

Question: How do i make it check to see whats available in the inventory?

Any scripts would be fantastic. something i can dissect and pick apart, to learn the inner workings, of course, i am completely happy with a "Here is a 200 line Script that does just that! written for you! for free! drop it on X object" :)

Comment
Add comment · Show 2
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 Julian-Glenn · Jul 17, 2010 at 11:46 PM 0
Share

You have created an entire Inventory system but can't figure out how to check it's ArrayList contents?

avatar image Peter G · Jul 18, 2010 at 12:00 AM 0
Share

He never said he was using an array list and honestly, he didn't say how is inventory system worked or if it is even set up in a way that would promote a good coding practices.

1 Reply

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

Answer by Peter G · Jul 18, 2010 at 12:28 AM

I'm not going to write a functional code for you. I will write a code missing your data, so that all's you have to do is plug it in. This way, you have to read through it, but have a guide.

  1. Make sure your inventory system is setup in such a way that this won't be too hard. Your inventory system should include variables for the current amount of all your resources. If this isn't setup, determine how you want to add to your counter, maybe OnCollisionEnter () { Resource++; }

  2. Set up your box to grab the inventory script then read the variable whenever it is needed. Not sure what GUI you are using. It will work very similarly no matter which.


var inventoryScript : #NameOfInventoryScriptHere#;

function Start () {

  FindObjectOfType(#NameOfInventoryScriptHere#); //needs cast in C# unless generic
  //cache a link to the inventory.

}

function OnGUI () { //You could use GUI layout also if(GUI.Button(#buttonArguments#)) { //create a button to respond if the user has enough of a certain resource. //this button might check gold and another might check food or something.

      if(inventoryScript.resource >= certainValue) {
      //see if we have enough of that resource

           inventoryScript.resource -= certainValue;
           CreateObjectAssociatedWithButton();
      }
  }

}

function CreateObjectAssociatedWithButton () { }

Comment
Add comment · Show 2 · 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
avatar image MikezNesh · Jul 18, 2010 at 01:55 AM 0
Share

Nice answer peter.

avatar image Silvio · Jul 18, 2010 at 04:14 AM 0
Share

Very nicely. I appreciate the code Peter G.

$$anonymous$$Y Inventory system has variables, tied to each unique object. The GUI spits out the number of For instance Gold coins stacked in the "Gui Box" or any other item that is "stackable"

I understand your code, and it was exactly was what i was looking for. Im not a programmer in any way. I take full scripts, and go through them figuring things out, modifying, or rewriting what i learned. (Best way i know how to learn)

Thanks again :P

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

No one has followed this question yet.

Related Questions

How to display textures that are in an array? 1 Answer

tooltip to show from array C# 1 Answer

Item HUD help 0 Answers

Toggle GUITexture V.2 1 Answer

Hotbar and item pickups? 1 Answer


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