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?

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?
      }
   }
}

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;
      }
}