Click here to Skip to main content
15,868,016 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
using System;

using System.Collections.Generic;
using UnityEngine;

public class destroyplayer : MonoBehaviour
{
    public event Action OnPlayerDeath;
    // Start is called before the first frame update
    void Start()
    {
        
    }

    // Update is called once per frame
    void Update()
    {
        
    }
    void OnCollisionEnter2D(Collision2D collison)
    {
        if (collison.collider.name == "placeholederduplicator")
        {
            OnPlayerDeath();
            FindObjectOfType<AudioManager>().Play("deathsound");
            Destroy(collison.gameObject);


        }
    }
}


What I have tried:

ive tried rewriting the code and looking at forums for an answer but nothing seems to work
Posted
Updated 28-Jul-20 19:26pm

1 solution

Object reference not set to an instance of an object
 
This error happens when you try to use a property or call a method of an object that is null. More details: here[^]
 
A simple use of Visual studio DEBUGGER can tell you the object because of which it is happening. Just look at the stack trace and put a debugger on that line. Check the objects of that line and see if any one is null and you are trying to use that objects property. Handle the same.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900