So the problem I’m having in Tile_Vainia is that when I add the ScenePersist.cs component the coins (or really whatever gameObject has this script attached to it) does not render when I hit play in unity. They’re visible in scene & game view. The coins are not invisible when I hit play they simply are not existing in my game. Below is my full code as I’ve tried to use the ScenePercist.CS from 2018 & 2021 Tile_Vainia but got the same results.
…
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.SceneManagement;
public class ScenePersist : MonoBehaviour {/*
int startingSceneIndex;
private void Awake()
{
int numScenePersist = FindObjectsOfType<ScenePersist>().Length;
if (numScenePersist > 1)
{
Destroy(gameObject);
}
else
{
DontDestroyOnLoad(gameObject);
}
}
// Use this for initialization
void Start () {
startingSceneIndex = SceneManager.GetActiveScene().buildIndex;
}
// Update is called once per frame
void Update () {
int currentSceneIndex = SceneManager.GetActiveScene().buildIndex;
if (currentSceneIndex != startingSceneIndex)
{
Destroy(gameObject);
}
}*/
void Awake()
{
int numScenePersists = FindObjectsOfType<ScenePersist>().Length;
if (numScenePersists > 1)
{
Destroy(gameObject);
}
else
{
DontDestroyOnLoad(gameObject);
}
}
public void ResetScenePersist()
{
Destroy(gameObject);
}
}
…