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 Hordaland · Feb 03, 2012 at 04:49 AM · arraysinventoryitemweapons

Creating an inventory/weapon array and ability to scroll through it

I'm horrible at arrays but I hope this might be a chance to truly learn how they work.

What I want is to create an inventory system similar to how you handle weapons in an fps. I've already created the script to pick an item up, making the item "equipped" and "accessed" through booleans. Accessed means the player owns the object and can choose to equip it. Equipped means that it's the item that the player is currently holding. I also have animations that will play whenever the player equips weapons and unequips them. And all the functions and stuff are pretty much finished as well.

But now I need some lines of code that makes the game skip the items that are not accessed yet so that when I use the scrollwheel to go through the items I will only equip items that I have access to and not the ones I am yet to encounter. I'm thinking maybe some loop searching through an array or something.

I guess the order of the events would be: Scrollwheel up/down -> if(itemcount > 2) { -> Unequipitem(); (Which includes the unequip-animation, yields everything until the animation is finished and then hides the weapon using a layer-switch) -> The loop to search for the next weapon -> When it's found use Equip(item); (item would be the name of the item to be equipped (or maybe a number could work as well))

Comment
Add comment
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

1 Reply

· Add your reply
  • Sort: 
avatar image
1

Answer by Berenger · Feb 03, 2012 at 05:39 AM

You'd have less trouble by having an AccessedWeapons array, that you update when you find a weapon. That way, you don't go through the array containing (if I understand correctly) all the existing items.

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 Hordaland · Feb 03, 2012 at 06:46 AM 0
Share

I see, thanks. Got any clues as to how I should begin coding the array?

avatar image Berenger · Feb 03, 2012 at 02:41 PM 0
Share

Well, one way would be to create it of the size maximal, the number of existing item. (Item[] accessedItem = new Item[biItemTotal]) then, with a counter nbAccessedItem, each time you pick one up accessedItem[ nbAccessedItem++] = pickedUpItem (make sure it doesn't exist already).

A list might be more appropriate though.

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

5 People are following this question.

avatar image avatar image avatar image avatar image avatar image

Related Questions

Creating a dynamic list in OnGUI 1 Answer

[C#]Inventory script help. 3 Answers

Stackable Inventory Item 1 Answer

how to detect wich item i have in my inevntory 0 Answers

Item and Inventory for a RPG game 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