D
D
DANICH702021-01-22 20:15:12
Unity
DANICH70, 2021-01-22 20:15:12

Is there a problem with the script?

Unity writes: "MissingReferenceException: The object of type 'GameObject' has been destroyed but you are still trying to access it.". I understand the essence of the error, but I don’t know how to issue it in the script. Script:

using UnityEngine;
using System.Collections;

public class Destroy : MonoBehaviour
{
    public GameObject explosion; //игровой объект для взрыва астеройда
    public GameObject playerExplosion; //игровой объект для взрыва корабля игрока

    void OnTriggerEnter(Collider other)
    {
        Instantiate(explosion, transform.position, transform.rotation); //создание взрыва при уничтожении астеройда
        if (other.tag == "Player" || other.tag == "Govno")
        {
            Instantiate(playerExplosion, other.transform.position, other.transform.rotation); //создание взрыва при уничтожении корабля игрока
        }
        Destroy(other.gameObject);
        Destroy(gameObject);
    }
}

Answer the question

In order to leave comments, you need to log in

1 answer(s)
F
freeExec, 2021-01-22
@DANICH70

One person should delete, not each other.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question