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 LeeVai · Oct 13, 2020 at 08:03 AM · item pickup

Item collection in specific sequence.

Hi. I have a simple 3D level with three items to be collected. I want them to be collected in order, that is to say, I want Items #2 and #3 to be "locked" until the preceding item is collected.
Right now, if you follow the game's instructions and UI prompts, its exactly as I want. But if a player happens to find item #2 or #3, the game UI gets discombobulated, and it is just not how I want it.

If this has been answered previously, help me find the thread.

 public class Collection : MonoBehaviour
 {
     public GameObject Prompt1;
     public GameObject Prompt2;
     public GameObject Prompt3;
     public GameObject Prompt4;
     
     // Start is called before the first frame update
     void Start()
     {
         Prompt1.SetActive(true);
         Prompt2.SetActive(false);
         Prompt3.SetActive(false);
         Prompt4.SetActive(false);
     }
 
     // Update is called once per frame
     void OnTriggerEnter(Collider player) 
     {
         Destroy(gameObject);
         print("Picked Up Item");
 
         
         if (gameObject.name == "potionBlue")
         {
             Prompt2.SetActive(true);
             Prompt1.SetActive(false);
             Prompt3.SetActive(false);
             Prompt4.SetActive(false);
         }
 
         if (gameObject.name == "plateRound")
         {
             Prompt1.SetActive(false);
             Prompt2.SetActive(false);
             Prompt3.SetActive(true);
             Prompt4.SetActive(false);
         }
 
         if (gameObject.name == "lotus")
         {
             Prompt1.SetActive(false);
             Prompt2.SetActive(false);
             Prompt3.SetActive(false);
             Prompt4.SetActive(true);
         }

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

2 Replies

· Add your reply
  • Sort: 
avatar image
0

Answer by Klarzahs · Oct 13, 2020 at 09:30 AM

Hi @Leevai,

it fails because you dont filter the pickup wheter the other objects have been found yet.
If you add e.g. a counter, which indicates the current object, you can easily check that inside each if statement.
Code:

 int counter = 0; //0 = no items, 1 = first item, 2 = second,...
 ...
 void OnTriggerEnter(Collider player){
   ...
   if(gameObject.name.equals("Potion blue") && counter == 0){
     //disable, enable stuff
     counter = 1; // player found first item
   }
   ..
 }

Please note that checking strings with "==" is error prone depending on your programming language, so its best-practice to use string.Equals("other string").
Also, did you add the above script to each go to check the OnTriggerEnter method? Then you probably have assigned the prompt1-4 at each script? Why not make them static variables? :)
Hope this helps

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
0

Answer by LeeVai · Oct 13, 2020 at 09:30 PM

Thank you for the insight. I had two things I wanted to happen involving 8 game objects: four clues (prompts1-4) and 4 collectible items (one being and invisible trigger for the first clue. As you find an item, the next one becomes active and collectible and you get the clue in the UI.
My original code had a mess of if checks in the OnTriggerEnter method and I was getting "Object of type has been destroyed but you are still tying to access it" error. Ultimately, I created two public methods (Clues and Items) and separated out the if checks. I called them in the OnTriggerEnter method. I also only SetActive(true) the first collectible gameObject in the sequence in the start method. I commented out the rest. I also commented out collectible items that have been destroyed in the if checks of the Items method. I'm sure that description is clear as mud, but it was a simple fix.

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

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

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

Item pick up script not working 2 Answers

Picking up and object and then dropping it again 0 Answers

Pick up Item 1 Answer

How to Pick up Items On Button Press and Add it To Visible Inventory 0 Answers

Different script for each item? 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