Reputation: 161
I would like my player to collide with an invisible collider and restart the scene right away but it seems like my script isn't working for some reason.
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.SceneManagement;
public class sceneRestart : MonoBehaviour
{
private void OnCollisionEnter2D(Collision2D platform)
{
if (platform.gameObject.tag == "Fall")
{
SceneManager.LoadScene("Main");
Debug.Log("Scene Restarted");
}
}
}
Upvotes: 1
Views: 31
Reputation: 161
The script is attached to the invisible collider, so it needs to check if the colliding object is the player:
public class sceneRestart : MonoBehaviour
{
private void OnTriggerEnter2D(Collider2D Col)
{
if (Col.gameObject.tag == "Player")
{
SceneManager.LoadScene("Main");
Debug.Log("Scene Restarted");
}
}
Upvotes: 1