using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class DontDestroy4 : MonoBehaviour
{
	static DontDestroy4 instance = null;

	void Awake()
	{
		if (instance != null && instance != this)
		{
			DestroyImmediate(gameObject);
		}
		else

		{
			instance = this;
			GameObject.DontDestroyOnLoad(gameObject);  // insures this object is not destroyed when loading a new scene

		}
	}

	// Start is called before the first frame update
	void Start()
    {
        
    }

    // Update is called once per frame
    void Update()
    {
		if (FindObjectOfType<PlayerMovement>() == null)
		{
			Destroy(gameObject);
		}
    }
}
