Okay, fair warning, I am very bad at getting my questions across, and I may just be over thinking this.
So, I have two scenes in my game (1. The ground floor of a house, 2. The upstairs floor of a house). On both floors there are objects that the player can loot for collectables. At the moment my inventory script consists of a DoNotDestoryOnLoad Function so that it persists through the loading of scenes.
My issue is after I have explored the ground floor and collected everything, then moved upstairs, If I was to then return downstairs, all of the collectables have respawned.
Is there a simple way of tracking what objects have been looted that will persist through loading and reloading a scene?
playerInventory Script
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class PlayerInventory : MonoBehaviour
{
public int playerBatteries = 0;
void Awake()
{
DontDestroyOnLoad(this);
}
}
Loot Script
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class Loot : MonoBehaviour
{
//Variables
public int batteries = 4;
//public int fuses = 4;
//public GameObject roomlight;
//private bool playerIsPresent = false;
// private bool roomIsLit = false;
//Script References
public PlayerInventory playerInventory;
void Awake()
{
if (playerInventory == null)
{
playerInventory = GameObject.Find("GameManager").GetComponent<PlayerInventory>();
}
}
// Update is called once per frame
void Update()
{
/*
if (roomlight.activeSelf == true)
{
roomIsLit = true;
}
else
{
roomIsLit = false;
}
*/
}
void OnTriggerStay(Collider other)
{
if (other.gameObject.tag == "Player" && Input.GetKeyDown(KeyCode.Space))
{
if (batteries > 0)
{
playerInventory.playerBatteries = playerInventory.playerBatteries + 1;
Debug.Log("Battery Taken");
batteries -= 1;
}
}
}
}
SceneSwitcher
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.SceneManagement;
public class Level1SM : MonoBehaviour
{
public Scene currentScene;
public string currentSceneName;
public UnityEvent switchLevel;
// Start is called before the first frame update
void Start()
{
currentScene = SceneManager.GetActiveScene();
currentSceneName = currentScene.name;
}
// Update is called once per frame
void Update()
{
}
void OnTriggerExit(Collider other)
{
if(currentSceneName == "Level 1")
{
SceneManager.LoadScene(1, LoadSceneMode.Single);
Debug.Log("Collide");
}
else if(currentSceneName == "Level 2")
{
SceneManager.LoadScene(0, LoadSceneMode.Single);
Debug.Log("Collide");
}
}
}