D
D
dark_spectator2018-11-10 22:39:03
C++ / C#
dark_spectator, 2018-11-10 22:39:03

Getting an error when deleting a prefab clone from the scene?

How to fix prefab deletion error? I'm very new to Unity and GameDev, would be very grateful for any hints.
Mistake:

MissingReferenceException: The object of type 'GameObject' has been destroyed but you are still trying to access it.
Your script should either check if it is null or you should not destroy the object.

the code:
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;

public class ClickHelper : MonoBehaviour {




    
 
public GameObject obj;

    public void OnCLick()
    {
        Instantiate(obj);
        Destroy(obj);
    }

    
}

Answer the question

In order to leave comments, you need to log in

1 answer(s)
G
GavriKos, 2018-11-10
@dark_spectator

What are you even trying to achieve with this code?
Is the error displayed on the second click? On what line?

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question