Y
Y
yraiv2020-05-17 15:50:57
Unity
yraiv, 2020-05-17 15:50:57

Why is the object not destroyed?

Why is the object not deleted, I need an object from the array to be created, and another one to be deleted, so that there is always only 1 object from the array of prefabs on the stage

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

public class BuyMobs : MonoBehaviour
{
    public GameObject[] Mobs;
    public GameObject Canvas;
    public int MobsNomer;
    private GameObject cyrGameObject;


    public void OnMouseDown()
    {
        if (cyrGameObject != null) Destroy(cyrGameObject);
        cyrGameObject = Instantiate(Mobs[MobsNomer], new Vector3(125, 310, 0), Quaternion.identity);
        cyrGameObject.transform.SetParent(Canvas.transform);
    }

}

Answer the question

In order to leave comments, you need to log in

1 answer(s)
K
Kot Kotov, 2020-05-17
@kot123123

try to check if the condition is correct, i.e. if the conditions are met, then it prints a word to the console

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question