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 /
avatar image
0
Question by Nosmo · Jul 20, 2016 at 02:39 PM · arraysobjectssequenceorder-of-execution

How can i pick up object is an order

I'm trying to pick up a series of objects and after all of them have been picked up code is executed to open a door.

I've been using an array but its tricky.

Can anyone help?

Comment
Add comment · Show 1
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 NoseKills · Jul 20, 2016 at 03:40 PM 0
Share

There's a 1000 ways to do this. We need to see some code to see what might be wrong and how to make it work.

2 Replies

· Add your reply
  • Sort: 
avatar image
0

Answer by redhotspike · Jul 20, 2016 at 08:52 PM

If I understand your question you're trying to pick up objects in an order and once all the items have been picked up (in the correct order) then you want to open a door.

Assuming I understand correctly, how about something like the following:

 public int TotalObjects; //there are more elegant ways to get this number but for this is just proof-of-concept
 
 int _itemsPickedUp = 0;
 bool _allItemsPickedUpInOrder = true;
 
 public void PickUpObject(YourFancyGameObject obj) {
    //in the object that you're picking up, have a public field that indicates what its order number is and compare it to the currently picked up items
    //this assumes zero-index
    if(obj.itemOrder != _itemsPickedUp) {
       _allItemsPickedUpInOrder = false;
    }
    
    _itemsPickedUp++; //increment when you pick up an object
    
    //if all items have been picked up
    if(_itemsPickedUp == TotalObjects) {
       //and all items were picked up in order
       if(_allItemsPickedUpInOrder) {
          OpenDoor(); //call the open door function
       } else {
          //if they weren't picked up in order
          //display message to user or reset objects?
       }
    }
 }
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 Vollmondum · Jul 20, 2016 at 08:51 PM

Easiest way is to create a tag, e.g. "doorKey", tag all those objects needed to be picked and run a simple script.

 var doorKeys: GameObject[];
 var openDoor: boolean;

 function Update()
 {
      doorKeys = gameObject.FindGameObjectsWithTag("doorKey");
 
       if(doorKeys.length == 0)
       {
               openDoor = true;
       }
 }
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

7 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

AudioClip Import Order Randomized? 4 Answers

How do I create and loop through a completely generic list in javascript? 1 Answer

Movement on roads issue 1 Answer

Iterating a GO through an array of transform positions 0 Answers

¿How Can I fill an array in runtime? 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