NullReferenceException: Object reference not set to an instance of an object BasicEnemyAI.OnTriggerEnter2D (UnityEngine.Collider2D collision) (at Assets/Scripts/BasicEnemyAI.cs:49)

I don’t know what is wrong here’s my code:

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

public class BasicEnemyAI : MonoBehaviour
{
[SerializeField] float Speed = 1f;
[SerializeField] float Health = 50;
[SerializeField] Transform DeathStart;
[SerializeField] GameObject Death;
Rigidbody2D _rb;
private Score _scoreManager;

void Start()
{
    _rb = GetComponent<Rigidbody2D>();
}

void Update()
{
    if (FacingRight())
    {
        _rb.velocity = new Vector2(Speed, 0f);
    }

    else
    {
        _rb.velocity = new Vector2(-Speed, 0f);
    }
}

bool FacingRight()
{
    return transform.localScale.x > Mathf.Epsilon;
}

void OnTriggerExit2D(Collider2D collision)
{
    transform.localScale = new Vector2(-(Mathf.Sign(_rb.velocity.x)), transform.localScale.y);
}

void OnTriggerEnter2D(Collider2D collision)
{
    if (collision.gameObject.tag == "Laser")
    {
        Health -= 10f;
        if (Health <= 0)
        {
            _scoreManager.Scoree += 100f;
            Instantiate(Death, DeathStart.position, DeathStart.rotation);
            Destroy(gameObject);
        }
    }
}

}

Judging from the error, either;

  1. _scoreManager is null
  2. _scoreManager.Scoree hasn’t been assigned a value
  3. Death is null
  4. DeathStart is null

I would personally suggest adding some null checking in your code to figure it out.