void Update() { if (!playerMovement.moveState.Equals(MoveState.ideal)) { time -= Time.deltaTime; if (time < 0) { GameObject path = new GameObject("path"); path.transform.parent = GameObject.FindGameObjectWithTag("PathLevel").transform; SpriteRenderer spriteRender = (SpriteRenderer)path.AddComponent(typeof(SpriteRenderer)); spriteRender.transform.position = gameObject.transform.position; spriteRender.sprite = path_sprite; DoNotDestroyMe doNotDestroyMe = path.AddComponent <DoNotDestroyMe>(); time = resetTime; } } }
void Awake() { //Check if instance already exists if (instance == null) { //if not, set instance to this instance = this; } //If instance already exists and it's not this: else if (instance != this) { //Then destroy this. This enforces our singleton pattern, meaning there can only ever be one instance of a GameManager. Destroy(gameObject); } //Sets this to not be destroyed when reloading scene DontDestroyOnLoad(gameObject); }