Enable and disable Children gameobject c#

Asked

Viewed 990 times

0

Well I made a script where activate and disable in a gameobject, I wanted to know how to activate and deactivate children also within this script

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

public class OBJETOS : MonoBehaviour
{
    public GameObject[] arrayObjetos;

    public void botoes(int num)
{
    for(int i = 0; i < arrayObjetos.Length; i++)
{
    if( arrayObjetos[num] == arrayObjetos[i])
{
    arrayObjetos[i].SetActive(true);
    }else{
    arrayObjetos[i].SetActive(false);
}
}
}
}
//sei que pode ser assim GameObject meuobjeto = GameObject.Find("meuobjeto");
// e assim tbm GameObject ChildGameObjeto1 = ParentGameObject.transform.GetChild (0).gameObject;

1 answer

0


this disables all children of gameobject that you put the script:

    foreach (Transform t in transform)
    {
          t.gameObject.SetActive(false);
    }
  • yes, more in the script where I did above, where I put it?

  • Basses? arrayObjects[i]. Setactive(true); }Else{ arrayObjects[i]. Setactive(false);

  • i did not tendi very well your question. From what I understand, you need to disable all fillhos of the object you put the script to. If that’s it, you can put it on void start() that when the game starts, this object will be disabled. But if that’s not it, please explain your question better

  • Ah ta, you want to deactivate the children of the object that will be deactivated?

  • I managed to add the forech and Gg vlw

Browser other questions tagged

You are not signed in. Login or sign up in order to post.