Unity get gameobject disabled

0

My player has a shield that is disabled in it, and I have a game manager that wants to take care when it can activate the shield or not when the player is instantiated in the scene the game manager does not find the component of the shield, this is because he is disabled, if active he finds more when he finishes the time of the shield he returns to not finding anybody else knows what it can be? I'm using:

   void Awake()
{
    if (_escudo != null)
    {
        _escudo =  GameObject.Find("Escudo"); //ele acha porque estou iniciando com o escudo ativado 

    }
    else
    {
        InvokeRepeating("checkComponentes", 0f, 2f);
    }
}

Here's the routine function:

 if (_component.input != 0 && _time >= _tempoDuracaoPoderes && _timeDelay <= 0)
    {// recebe o aperto do botao e verifica outras condições antes de ativar 

        StartCoroutine(EscudoForca()); // responsavel por controlar o tempo do escudo
        _buttonescudoForca.enabled = false;
        _time = 0;                    
    }
    else
    {
        _time += Time.deltaTime;
        _timeDelay -= Time.deltaTime;
    }

}
IEnumerator EscudoForca()
{
    _escudo.SetActive(true); //escudo ativo
    _uiEscudo.SetActive(true);// efeito de lente ativa
    statusBar.fillAmount = 1; 
    anim.SetBool("ativado", true);
    _timeDelay = 5.0f;
   // _escudo = GameObject.Find("Escudo");

    yield return new WaitForSeconds(_tempoDuracaoPoderes);

   // _escudo = GameObject.Find("Escudo");
    _escudo.SetActive(false);
    _uiEscudo.SetActive(false);
    statusBar.fillAmount = 0;
    anim.SetBool("ativado", false);




}

The question is do I get the GameObject disabled to be able to activate later, just like I already do this more if the PLAYER is on the screen if instantiated does not work. Thanks in advance ...

    
asked by anonymous 01.06.2018 / 03:55

1 answer

1

The GameObject.Find function only returns active objects, so returning inactive objects in the scene uses the Resources.FindObjectsOfTypeAll (Be very careful to use this, it consumes a lot of processing)

If your shell object has a script it is easy, otherwise it is better to create a manager that has the reference of your object somewhere to have this access;

Another way if you access the parent gameobject using GetComponentsInChildren ()

There's a similar question: LINK

    
06.06.2018 / 00:55