Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 12 Next capture
2021 2022 2023
1 capture
12 Jun 22 - 12 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 /
  • Help Room /
avatar image
0
Question by metallica6474 · Sep 09, 2016 at 05:40 PM · collidersinventoryinventory system

Can someone help me with getting a script that'll recognize when I have a certain amount of rocks in my inventory?

Hello, I made a post about this on here about 5-6 months ago, and i'm still having trouble with it. User tanoshimi gave me a snippet of the script that I needed, but since it was incomplete, there wasn't much I could do with it. Anyways, In my game, I need to go around 3 different islands to collect a total of 60 rocks, and after I have all 60 rocks collected, I need to walk into a collider that is a trigger thats on my main island, and when I walk into the collider, it'll cut to an animation and the rocks will be aligned to spell out "S.O.S" But the problem is, I have no idea how to get a script that'll detect when I have 60 rocks in my inventory. I'm pretty sure I can handle the rest, but all I need is a script that'll detect when I have 60 rocks, and then to turn on the collider. If someone can direct me where to go to find out how to get this script, or be nice enough to actually make a script, it'll be greatly appreciated. The inventory script I am using is the free one called "Inventory Master"

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 metallica6474 · Sep 09, 2016 at 03:34 PM -1
Share

Here's the link to the post where "Tanoshimi" gave me an incomplete script.

avatar image metallica6474 · Sep 09, 2016 at 03:52 PM 0
Share

Or maybe a simpler way would be to make a script where it goes like, when all objects tagged "Stones" are all gone, the collider activates? That seems like it would be easier.

avatar image TBruce · Sep 09, 2016 at 05:58 PM 0
Share

@tanoshimi gave you all that you really needed.

Remember this is a site for people with Unity related questions. It is not a site to $$anonymous$$ch people how to program (there are more than enough of those out there).

tanoshimi is assu$$anonymous$$g that you have some basic knowledge of creating classes in C#. So as he wrote in his reply the snippet

needs to be contained in a proper C# class definition, in which case "playerInventory" becomes a slot exposed in the inspector panel onto which you can drag and drop the player inventory.

What this means is you need to supply this

 using UnityEngine;
 using System.Collections;
 using System.Collections.Generic; // this is needed for Lists
 
 public class $$anonymous$$yClassName : $$anonymous$$onoBehaviour
 {
     // SNIPPET CODE HERE
 }

where // SNIPPET CODE HERE is the snippet supplied by tanoshimi. So basically the resulting class would look something like this

 using UnityEngine;
 using System.Collections;
 using System.Collections.Generic; // this is needed for Lists
 
 public class $$anonymous$$yClassName : $$anonymous$$onoBehaviour
 {
     [Tooltip("Drag your player's inventory into this slot")]
     [SerializeField]
     private Inventory playerInventory; 
 
     [Tooltip("Set this to the ID of the stone in your inventory system")]
     [SerializeField]
     private int stoneID;
 
     // Something entered the spot...
     void OnTriggerEnter(Collider other)
     {
         // .. was it the player?
         if (other.CompareTag("Player") )
         {
             // If so, rummage through their inventory
             List<Item> items = playerInventory.getItemList();
 
             // and count up how many stones they have
             int numStones = 0;
             for(int i=0; i<items.Count; i++)
             {
                 if (items[i].itemID == stoneID)
                     numStones++;
             }
             // Do they have enough?
             if(numStones >= 60)
             {
                 SOSAnimation.Play();
             }
         }
     }
 }

But as tanoshimi stated you do need to set up everything in the inspector properly.

avatar image metallica6474 TBruce · Oct 07, 2016 at 03:02 PM 0
Share

Thanks for all the help, I do really appreciate it. Although, even though I clearly have "SOSAnimation" in my game, it says that it doesn't exist in its current context.

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

Inventory & Co. suggestioni? 2 Answers

Display list as UI or GUI 0 Answers

Concept of inventory system 0 Answers

Inventory System ? 0 Answers

Index was out of range. error 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