-
::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()
{
}
}
::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);
}
}
}
::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.
::Don’t worry I figured it out. Thank you.