First, please use code tags .
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.SceneManagement;
public class AreaExit : MonoBehaviour {
public string areaToLoad;
public string areaTransitionName;
// Start is called before the first frame update
void Start() {
}
// Update is called once per frame
void Update() {
}
private void OnTriggerEnter2D(Collider2D other) {
if(other.tag == "Player")
Debug.LogError("Collisiondetected,TryingtoLoad");
{
SceneManager.LoadScene(areaToLoad);
}
}
}
Your if-statement seems to be incorrect here. The SceneManager.LoadScene line is not part of the condition and will run regardless. You probably meant to do this:
private void OnTriggerEnter2D(Collider2D other) {
if(other.tag == "Player") {
Debug.LogError("Collisiondetected,TryingtoLoad");
SceneManager.LoadScene(areaToLoad);
}
}