Forum begins after the advertisement:


[Part 5] I keep getting a console error from the game manager script

Home Forums Video Game Tutorial Series Creating a Metroidvania in Unity [Part 5] I keep getting a console error from the game manager script

Viewing 4 posts - 1 through 4 (of 4 total)
  • Author
    Posts
  • #13622
    demilade
    Participant

    Here is my code

    using System.Collections;
    using System.Collections.Generic;
    using UnityEngine;
    
    public class Gamemanagerscript : MonoBehaviour
    {
        public string TransitionedFromScene;
        public static GameManager Instance { get; private set; }
    
        private void Awake()
        {
            if(Instance != null && Instance != this)
            {
                Destroy(gameObject);
            }
            else
            {
                Instance = this;
            }
            DontDestroyOnLoad(gameObject);
        }
        // Start is called before the first frame update
        void Start()
        {
            
        }
    
        // Update is called once per frame
        void Update()
        {
            
        }
    }
    #13623
    demilade
    Participant

    This is my code now

    using System.Collections;
    using System.Collections.Generic;
    using UnityEngine;
    using UnityEngine.SceneManagement;
    
    
    public class Scenetransition : MonoBehaviour
    {
        [SerializeField] private string TransitionTo;
        [SerializeField] private Transform StartPoint;
        [SerializeField] private Vector2 ExitDirection;
        [SerializeField] private float ExitTime;
    
        // Start is called before the first frame update
        void Start()
        {
             if(GameManager.Instance.TransitionedFromScene == TransitionTo)
            {
                PlayerController.Instance.transform.position = StartPoint.position;
            }
        }
    
        private void OnTriggerEnter2D(Collider2D _other)
        {
            if (_other.CompareTag("Player"))
            {
                GameManager.Instance.TransitionedFromScene = SceneManager.GetActiveScene().name;
    
                SceneManager.LoadScene(TransitionTo);
            }
        }
    }
    #13629
    Joseph Tang
    Moderator

    Thank you for the provision of your code, could you provide us with what error you received in the console?
    If you are able to find what kind of error result is produced in the Console and give us the reference number to it, it could also help with identifying the core issue of the error.

    Looking at your code, it seems most probable it could be a NullReferenceException error for any of the [SerializeField] variables. Still, it’d be more identifiable with the console error.

    #13631
    demilade
    Participant

    Don’t worry I figured it out. Thank you.

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

Go to Login Page →


Advertisement below: