im new to unity and i was working on a 2d game when i hit the death cube i dont die i stand on top

using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.SceneManagement;

public class FinshLine : MonoBehaviour
{
    // Start is called before the first frame update
    void Start()
    {
       
    }

    // Update is called once per frame
    void Update()
    {
       
    }

    private void OnCollisionEnter2D(Collision2D other)
    {
       if(other.gameObject.CompareTag("Player"))
       {
           SceneManager.LoadScene("level12");
       }
    }
}

In your title you talk about a “death cube” but you show code for the “FinishLine”. Does that not work either?

Either way, check if your code runs at all. Place Debug.Log() messages to see if it does. If it does, check if your condition gets entered. If so, check why you dont die despite expecting to die. If not, check why that condition is not true. And so on.

Try the following:

Make sure is “Is Trigger” is checked.

9203697--1283913--upload_2023-8-9_0-16-9.png

Then in your scipt:

private void OnTriggerEnter(Collision2D other)
    {
       if(other.gameObject.CompareTag("Player"))
       {
           SceneManager.LoadScene("level12");
       }
    }

To add to the above comment: OnTriggerEnter only works for 3D colliders. Make sure you use OnTriggerEnter__2d__ if you are using 2D colliders.