D
D
DANICH702021-01-30 19:29:10
Unity
DANICH70, 2021-01-30 19:29:10

Problems with SetActive?

The question is, I made the program hide objects with the same tag at the beginning, and after a collision with a trigger, show these objects. But. Why doesn't it show.

using UnityEngine;
using System.Collections;
using UnityEngine.SceneManagement;

public class Destroy : MonoBehaviour
{
    public GameObject explosion; //игровой объект для взрыва астеройда
    public GameObject playerExplosion; //игровой объект для взрыва корабля игрока
    
    void Start()
    {
        var objsf = GameObject.FindGameObjectsWithTag("Lose");
        for (int i = 0; i < objsf.Length; i++)
        {
            objsf[i].SetActive(false);
        }
    }

    void OnTriggerEnter(Collider other)
    {
        if (other.tag == "Player")
        {

        }

        var objs = GameObject.FindGameObjectsWithTag("Lose");
        for (int i = 0; i < objs.Length; i++)
        {
            objs[i].SetActive(true);
        }

        Destroy(gameObject);
        Destroy(other.gameObject);
    }
}

Answer the question

In order to leave comments, you need to log in

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

The question why is answered by the debugger, not the forum. Have you checked that you have

var objs = GameObject.FindGameObjectsWithTag("Lose");
finds anyone to show?

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question