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 madmike6537 · Feb 01, 2013 at 05:02 PM · listinventorycrafting

Looking for some help with theory on my crafting system

Hi Unity,

I am about to start creating my own crafting system and I am looking for some help on my theory before I jump in head first.

What I have today is a basic inventory system based around an Item script which defines what an item is and gives it things like an icon, tooltip, and other properties.

I have the ability to collect items in the game and add them to my inventory.

Now what I am looking to do is create a GUI window that allows you to put items in it and checks to see if you have certain items, if you have those items, in a gui box to the right a craftable item will show up.

So here is how I plan to implement this - and I am trying to find a better way to set up the recipe system:

Using OnMouseDown to detect if player has clicked on crafting table, if so GUI window pops up.

Use a for Loop to loop through current items in the players inventory.

(Now here is where I need some help to figure the best way to do this)

My original thought, which I think is probably terrible, is have a seperate set of variables in my crafting class, basically one variable for every item in the game.

As I loop through the player inventory, I can check if item.name == whateverItem. If it is, I increase a counter for that item.

Then after the for loop I can check the count for all my variables and if I have one of each of the items needed for itemX, then that icon shows up.

Something maybe like this?

 private string basicWoodName = "basicWood"
 private int basicWoodCount= 0;
 
 private string basicStoneName = "basicStone"
 private int basicStoneCount = 0;
 
 for(int cnt; cnt < itemScript.playerInventory.count; cnt++)
 {
   if(itemScript.playerInventory[cnt].name == basicWoodName)
   {
   basicWoodCount++;
   }
 
     if(itemScript.playerInventory[cnt].name == basicStoneName )
   {
   basicStoneCount++;
   }
 
 
 }
 //I would need one of these for every item.. ouch
 
 //Then I would need recipe's - something like this maybe? (terrible I know)
 if(basicWoodCount == 6 && basicStoneCount == 1)
 {
   //Show GUI Icon for a Sword
 }
 
 //I would need one of these for every possible combination.. Ouch
 

I would like to just use a List for this somehow, but i cant figure out how I would access the invidivual items in the list to see if I have what I need.

Of course I will need to add a lot more to this script but I am just trying to formulate the basic idea of how this is going to work.

Thoughts on a better way to do this before i start?

Thanks!

Comment
Add comment · Show 4
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 Julien-Lynge · Feb 01, 2013 at 05:31 PM 0
Share

This question isn't something we can answer for you in 500 words or so. To give you a good response would require a conversation. Unity Answers isn't for conversations - please move this to the forums ins$$anonymous$$d, where you're much more likely to get good feedback.

avatar image madmike6537 · Feb 01, 2013 at 05:41 PM 0
Share

Thanks Ill try there as well.

avatar image electricsauce · Feb 09, 2013 at 05:06 AM 0
Share

Try these tutorials. They are extremely long, but he goes into detail on how to set up an item/attribute system.

http://www.burgzergarcade.com/hack-slash-rpg-unity3d-game-engine-tutorial

avatar image madmike6537 · Feb 09, 2013 at 05:09 AM 0
Share

Ya I have actually based some of my current system off of Petey's. I have a good working system going now - might not be the most efficient but it works well.

Thanks for the link though!

2 Replies

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

Answer by madmike6537 · Feb 09, 2013 at 05:01 AM

I ended up going with a different solution to solve this problem a bit more simple way. If anyone is interested in how this was done feel free to PM me.

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
avatar image
1

Answer by Vonni · Feb 01, 2013 at 05:31 PM

Why loop through your inventory every time? You could just have a class like "CurrentItems" and just add and subtract from CurrentItems.wood--; as you pick em up and use them. And simply display something using those variables?

EDIT: (Your comments)

Hmm, I can't think of a way to have em in some list without having to keep checking the list to see what the amounts are. But I guess it wouldnt take that long to check the inventory. But maybe use ENUMS instead of string to make it faster. Like:

 enum Material {
     Stone,
     Wood,
     Glass,
     None
 }

and in your Inventory (class)(your original) you could have

 class Inventory {
    var material : Material;
    var ikon : Texture;
    var name : String;
    //etc whatever you have in this
 }

and then (don't know if you are using LIST) but if you aren't: var playerInventory : List. = new List.();

Comment
Add comment · Show 1 · 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 madmike6537 · Feb 01, 2013 at 05:44 PM 0
Share

Hmm so basically when I add the items in my inventory also add them to another class called currentItems and check there for what I have? $$anonymous$$akes sense.

What about my variable method though, I assume I would still have to use that but just put it in another class. Can you think of a way to use a list for that ins$$anonymous$$d of a variable for each item's name and count?

I am going to leave this open for just a little bit and see if I can get some other ideas as well. Thanks very much!

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

12 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

Related Questions

A node in a childnode? 1 Answer

Problem with dropping items from my inventory 0 Answers

Problem at crafting 1 Answer

Can someone help me with an inventory? 1 Answer

List array in GUI.Box 0 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