Hello everyone,
I’m developing a VR mini game in which the user looks for objects inside a room. At the center of the scene there is something like a tv screen, where an image of the to-be-searched object is being displayed. So, at the beginning the user takes a look at the tv screen to see which object they have to look for. Then, they start searching within the room for this object. Once they find it, they have to press the trigger button and the same scene is reloaded. After reloading, a new object is being displayed on the tv screen. This goes on until the user searches for all the objects at least once.
What I have until now is shown below:
using System.Collections;
using System.Linq;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.SceneManagement;
public class TrialHandler : MonoBehaviour
{
public static TrialHandler Instance;
public List<GameObject> objectsList;
private int currentObject;
[HideInInspector] public static int trialNum = 0;
private void Awake()
{
objectsList = objectsList.Where(item => item != null).ToList();
if (Instance = null)
{
Instance = this;
}
else if (Instance != null)
{
Destroy(gameObject);
return;
}
DontDestroyOnLoad(gameObject);
}
void Start()
{
currentObject = Random.Range(0, objectsList.Count);
objectsList[currentObject].SetActive(true);
trialNum += 1;
}
void Update()
{
objectsList.RemoveAt(currentObject);
objectsList[currentObject].SetActive(false);
}
On the tv screen, images of the to-be-searched objects are being displayed. All these images are present in the scene but deactivated. When the scene starts, I select one image randomly and activate it. This way an image of the to-be-searched object is being displayed and prompts the user on which object to look for.
I have several problems:
- Although the list becomes populated the first time the scene loads, from the second load onwards the list elements in the inspector are empty ( “Missing (GameObject)”). However, the images are being displayed properly each time I reload the scene.
- Despite the fact that I am trying to get rid off the image(s) that were previously selected, so they don’t get displayed again, I don’t get it right. Random images are getting displayed each time, but this means that some might appear 2 or 3 times, instead of 1.
Any advice would be very much welcomed.
Thanks for your time.