Forum begins after the advertisement:


[Part 7] SceneManager doesn’t exist error

Home Forums Video Game Tutorial Series Creating a Metroidvania in Unity [Part 7] SceneManager doesn’t exist error

Viewing 3 posts - 1 through 3 (of 3 total)
  • Author
    Posts
  • #19012
    Tyler Fruge
    Level 5
    Participant
    Helpful?
    Up
    0
    ::

    Trying to do the save system and i keep getting an error that says “The name ‘SceneManager’ does not exist in the current context” for both the GameManager and bench scripts.

    GameManager:

    using System.Collections;
    using System.Collections.Generic;
    using UnityEngine;
    
    public class GameManager : MonoBehaviour
    {
        public string transitionedFromScene;
    
        public Vector2 platformingRespawnPoint;
        public Vector2 respawnPoint;
        [SerializeField] Bench bench;
        public GameObject faithstealer;
        public static GameManager Instance { get; private set; }
        private void Awake()
        {
            SaveData.Instance.Initialize();
    
            if (Instance != null && Instance != this)
            {
                Destroy(gameObject);
            }
            else
            {
                Instance = this;
            }
            SaveScene();
    
            DontDestroyOnLoad(gameObject);
            bench = FindObjectOfType<Bench>();
        }
        public void SaveScene()
        {
            string currentSceneName = SceneManager.GetActiveScene().name;
            SaveData.Instance.sceneNames.Add(currentSceneName);
        }
        public void RespawnPlayer()
        {
            SaveData.Instance.LoadBench();
            if (SaveData.Instance.benchSceneName != null) //load the bench's scene if it exists.
            {
                SceneManager.LoadScene(SaveData.Instance.benchSceneName);
            }
            if (SaveData.Instance.benchPos != null) //set the respawn point to the bench's position.
            {
                respawnPoint = SaveData.Instance.benchPos;
            }
            else
            {
                respawnPoint = platformingRespawnPoint;
            }
    
    
            PlayerController.Instance.transform.position = respawnPoint;
    
            StartCoroutine(UIManager.Instance.DeactivateDeathScreen());
            PlayerController.Instance.Respawned();
        }
    }

    bench:

    using System.Collections;
    using System.Collections.Generic;
    using UnityEngine;
    
    public class Bench : MonoBehaviour
    {
        public bool interacted;
        // Start is called before the first frame update
        void Start()
        {
    
        }
    
        // Update is called once per frame
        void Update()
        {
    
        }
        private void OnTriggerStay2D(Collider2D _collision)
        {
            if (_collision.CompareTag("Player") && Input.GetButtonDown("Interact"))
            {
                interacted = true;
    
                SaveData.Instance.benchSceneName = SceneManager.GetActiveScene().name;
                SaveData.Instance.benchPos = new Vector2(gameObject.transform.position.x, gameObject.transform.position.y);
                SaveData.Instance.SaveBench();
            }
        }
        private void OnTriggerExit2D(Collider2D _collision)
        {
             if (_collision.CompareTag("Player"))
            {
                interacted = false;
            }
        }
    }
    #19018
    Tyler Fruge
    Level 5
    Participant
    Helpful?
    Up
    1
    ::

    UPDATE: ok so i think the issue was that i didn’t have “using UnityEngine.SceneManagement;” in the game manager or the bench scripts.

    has upvoted this post.
    #19019
    Terence
    Level 31
    Keymaster
    Helpful?
    Up
    0
    ::

    Yup. This was one issue that the AI helper would’ve been easily able to help you with.

Viewing 3 posts - 1 through 3 (of 3 total)
  • You must be logged in to reply to this topic.

Go to Login Page →


Advertisement below: