I have a list with 7 elements in Unity. At the beginning of the scene, one element is getting activated for 3 seconds and then deactivated. Then the user has to search for this element in the scene and once he/she finds it to press the trigger button to advance to the next scene. What I want to achieve is to remove the elements that have already been activated, so the user does not see them in the next scenes. So, if in the first scene the element 6 was activated, then in the second scene any element can be activated but not 6. And so on and so forth for the next scenes. Until now, I have the script below:
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class TrialHandler : MonoBehaviour
{
public static TrialHandler instance;
public List<GameObject> objectsList = new List<GameObject>();
private int currentObject;
private float timer;
[HideInInspector] public static int trialNum = 0;
private void Awake()
{
objectsList.RemoveAll(item => item = null);
instance = this;
DontDestroyOnLoad(this.gameObject);
}
void Start()
{
currentObject = Random.Range(0, objectsList.Count);
objectsList[currentObject].SetActive(true);
trialNum += 1;
}
// Update is called once per frame
void Update()
{
timer += Time.deltaTime;
if (timer >= 3.0f)
{
objectsList[currentObject].SetActive(false);
}
}
}
It works fine for the most part except that it repeats elements that the user has already seen as he/she goes over the scenes. I have put this code objectsList.RemoveAll(item => item = null); but it doesn't seem to get rid off the elements that have been deactivated once a new scene is loaded.
Any ideas? Thanks in advance.
Update: The problem seems to be that when the scene starts all the elements are being deactivated (with only one random element being activated). Because of this when the next scene loads the list does not become populated with the remaining elements. However, I cannot activate all the elements from the very beginning because I want only one to be displayed at each scene.