Forum begins after the advertisement:
-
::there is an error that happens when my player touches the scene transition in makes the player not enter the next scene
the error points out the NullReferenceException: Object reference not set to an instance of an object
SceneTransition.OnTriggerEnter2D (UnityEngine.Collider2D _other) (at Assets/scripts/SceneTransition.cs:37)
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;
private void Start()
{
if(transitionTo == GameManager.instance.transitionFromScene)
{
PlayerController.instance.transform.position = startPoint.position;
StartCoroutine(PlayerController.instance.WalkIntoNewScnene(exitDirection, exitTime));
}
StartCoroutine(UiManager.instance.sceneFader.fade(ScreenFader.fadeDirection.Out));
}
private void OnTriggerEnter2D(Collider2D _other)
{
if (_other.CompareTag("Player"))
{
GameManager.instance.transitionFromScene = SceneManager.GetActiveScene().name;
PlayerController.instance.pState.transition = true;
StartCoroutine(UiManager.instance.sceneFader.FadeAndLoadScene(ScreenFader.fadeDirection.In, transitionTo));
}
}
}
::Hi Haydn,
The error should be here:
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;
private void Start()
{
if(transitionTo == GameManager.instance.transitionFromScene)
{
PlayerController.instance.transform.position = startPoint.position;
StartCoroutine(PlayerController.instance.WalkIntoNewScnene(exitDirection, exitTime));
}
StartCoroutine(UiManager.instance.sceneFader.fade(ScreenFader.fadeDirection.Out));
}
private void OnTriggerEnter2D(Collider2D _other)
{
if (_other.CompareTag("Player"))
{
GameManager.instance.transitionFromScene = SceneManager.GetActiveScene().name;
PlayerController.instance.pState.transition = true;
StartCoroutine(UiManager.instance.sceneFader.FadeAndLoadScene(ScreenFader.fadeDirection.In, transitionTo));
Debug.Log(UiManager.instance);
Debug.Log(UiManager.instance.sceneFader);
}
}
}
Can you put the lines highlighted in green above and show me the Console output? And show me your Inspector for the UIManager as well.
Advertisement below: