PickUp objects in the correct sequence

Hello there,

This time i am getting a little confuse with a simple script used to pick objects up in the correct sequence from a list i Made. The funny thing here is that the code works perfectly sometimes but sometimes it doesn’t.
And I am struggling to find a logical reason why and when this happen.

The code that follow simply should say if you pick the element 0 on the list as the first object that is good collect it and keep going with the element 1 and 2. Once you collect the last object (temp = 2) the level should be completed and the next level animation will start.
On the other hand if you pick the object not in the established sequence The game will end.

I am pretty sure this script can be re-Rewritten in a nicer and more logical way so HELP ME GUYS.

using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.SceneManagement;
using UnityEngine.Playables;
public class Sequence : MonoBehaviour

{
    //public  Collect collect;
    public GameObject Player;
    public GameObject cam_L2;
    public MyInvento lista;
    public PlayableDirector timeline_L2;
    public Transform NextLevel;
    public GameManager gameManager;
    int temp = 0;

   


    void OnTriggerEnter(Collider col)
    {
       
        if (lista.MyGem.Contains(col.gameObject))
        {
            if (lista.MyGem.IndexOf(col.gameObject) == temp)
            {
                Debug.Log("Pickup Collected");
                temp += 1;

                if (temp == 2)
                {

                    Debug.Log("Level Complete");
                    cam_L2.SetActive(true);
                    timeline_L2.Play();
                    Player.transform.position = NextLevel.transform.position;

                }
            }
            else
            {
                FindObjectOfType<GameManager>().EndGame();

            }
          
           

        }
      

    }
}

Everything looks fine. Maybe you have problems when you’re adding “MyGem” to “lista”.
Maybe you don’t erase “lista” when you pass to the next level.

This piece of code seems to be ok.

Place some logs and see what really happens.

temp is 0 only once. Debug.Log it.