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
1
Question by Riftcaller.Games · Oct 22, 2011 at 11:10 AM · javascriptguiinventory

Inventory Help

I've been silently searching for several weeks now in an effort to learn how to accomplish what I'm trying to do with an Inventory system on my own, but I've decided to try and ask for some guidance. I've done thorough searches using Google and the native searching capabilities of the site, but I haven't quite found a script that accomplishes what I have in mind. I've noticed that detail is key when asking for help around here, so I'll try to be as specific as possible.. starting with a description of my game project:

"The game is predominantly action-based, using tool items to both explore areas around the village and to tend crops on soil plots. The player must build relations with the villagers in order to glean information concerning a mystery, and does this via conversation, gifts, and events. There are RPG elements, but the genre would be better classed as a casual/action game in a fantasy setting."

I've learned quite a bit about the value of prefabs from looking into some available inventory scripts to see how the item database is managed, so I have put together a script with the following vars to set via the inspector for each item:

 class Item {
 
 var name : String;
 var icon : Texture; // 50x50 icon texture that represents the item
 var type : String; // Set whether the item is a tool, ingredient, dish, etc.
 var mesh : Transform;
 var consumable : Boolean;
 var giftable : Boolean; // Flags if the item is able to be given to an NPC
 var sellValue : int;
 var buyValue : int;
 var regenValue : float; // If consumable, sets the percentage of recovery
 var index : int; // Means of grouping like items via numbers
 var description : Texture; // 2d Texture used to supply layer with item information
 
 }

I'm aiming for a predominantly mouse-based control system in the game overall, but the inventory is my primary concern. The gist of the controls are summarized here:

 // Slots should be arranged in a 6x4 grid amounting to a total of 24 slots; 6 columns, 4 rows.
 // The Inventory can be opened or closed by clicking on an HUD icon or by pressing the I key.
 // Items within the Inventory can be reorganized by dragging and dropping.
 // Items are used and tools are equipped by double-clicking.
 // Delete items from the inventory by dragging and dropping the item to a delete icon.
 // Items can be selected and information viewed by clicking once on the item.
 // Items CANNOT be dragged and dropped outside of the inventory, only reorganized within the pane.

Looking into Unity's documentation and the API, I managed to create a series of three GUI Texture buttons as a temporary means of triggering the game menu scripts, but that is as far as I was able to get without now seeking some help. I've grabbed a few books on C#, but for the time being I feel most comfortable with Unityscript's syntax.

This is, so far, the largest hurdle in my learning experience so far with Unity, and I'm very much impressed with the available documentation! I come from an artistic background, but have always enjoyed designing frameworks for my ideas and dabbling in Ruby when my game project was still based in the RPG Maker XP engine.

Comment
Add comment · Show 6
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 syclamoth · Oct 22, 2011 at 08:58 AM 0
Share

You know, this is another one of those times when I would point you towards my inventory script , but you are asking for a bit more functionality here! The dragging and dropping inside of a 6x4 grid should be achieveable by reworking a few specifics of how the GUI parts of it works, and as for the rest of it you just need to add in more features to the 'Item' interface to allow for buy and sell prices etc. Unfortunately, my script is in C#, but it's not that hard to follow. I'm actually not sure how I would do it in javascript.

avatar image Riftcaller.Games · Oct 22, 2011 at 09:09 AM 0
Share

Thanks for the reply, syclamoth! I was actually looking over your script while I was waiting for a response and noticed that it was in C#, which handles Arrays and other features a bit differently than Unity's Javascript. And I also remember reading somewhere that serialization is only truly possible in C#, which has me wishing I had a better grasp on the syntax. I think I'll plug your script in and give it a run, though, since it's a well-written script.

EDIT// I'm getting an error at (60,23) "The type or namespace name '$$anonymous$$onoBehaviour' could not be found."

avatar image syclamoth · Oct 22, 2011 at 09:54 AM 0
Share

You need to put in 'using UnityEngine' at the top. Along with 'using System.Collections.Generic' and 'using System.Collections'.

avatar image Riftcaller.Games · Oct 22, 2011 at 10:56 PM 1
Share

Edited to include those lines, but I'm receiving other errors that I'm not sure how to fix -- mostly due to my inexperience with C#. I did some additional searching and I'm looking into Little Angel's "Inventory $$anonymous$$anager 2.0", which seems to implement what I'm after for a pretty reasonable price. Have you had experience with this system, syclamoth?

As for the errors I've received with the script:

(26, 31) : Operator '+' cannot be applied to operands of type 'float' and 'method group'.

(49, 21) : Cannot implicitly convert type 'UnityEngine.Texture2d[]' to 'UnityEngine.Texture2d'.

(50, 41) : The best overloaded method match for 'UnityEngine.GUILayout.SelectionGrid(int, string[], int, params UnityEngine.GUILayotOption[])' has some invalid arguments.

(50, 41) : Argument '#2' cannot convert 'UnityEngine.Texture2d' expression to type 'string[]'.

avatar image Bovine · Oct 27, 2011 at 10:51 PM 0
Share

We have an inventory system for our RPG. Sadly, I can't share that with you but I recommend checking out EZGUI with which it is built. EZGUI is available in the asset store and will save you a lot of work and speed up your GUI rendering too!

Our Inventory http://forum.anbsoft.com/viewtopic.php?f=17&t=2440

EZGUI http://www.anbsoft.com/middleware/ezgui/

Show more comments

0 Replies

· Add your reply
  • Sort: 

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

4 People are following this question.

avatar image avatar image avatar image avatar image

Related Questions

Remove Items and Item Tooltips 0 Answers

Cropped Label Problem - Big Font - Unity3D 1 Answer

OnGUI and Event.current 2 Answers

How To Make A Numeric Inventory System? 0 Answers

inventory system - change GUI.DrawTexture texture 3 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