- Home /
How to Deactivate Gameobjects Array in Unity 4?
Hi! Help me please, i have
`GameObject [] arrayItems;`
How to deactivate and activate all items in
arrayItems[i]
script c#
Answer by moghes · Jun 08, 2013 at 10:17 AM
foreach (GameObject obj in arrayItems)
{
obj.active = true;
}
this would activate all gameobjects in the array. Did not test though, check if you have any problem with this, leave a comment.
this is my code(C#):
using UnityEngine; using System.Collections; public class TestCodeCS : $$anonymous$$onoBehaviour { public int numSelectors = 5; GameObject[] selectorArr;
void Start()
{
selectorArr = new GameObject[numSelectors];
for (int i = 0; i < numSelectors; i++)
{
GameObject go = Instantiate((Resources.Load("_prefabs/prefab_Cube")), new Vector3((float)i, 1, 0), Quaternion.identity) as GameObject;
go.transform.localScale = Vector3.one;
selectorArr[i] = go;
}
Deactivate();
}
void Deactivate(){
foreach (GameObject obj in selectorArr)
{ obj.activeSelf = false;
} } }
after run,i get message(warning): UnityEngine.GameObject.active' is obsolete:
GameObject.active is obsolete. Use GameObject.SetActive(), GameObject.activeSelf or GameObject.activeInHierarchy.'
How to fix?
Your answer

Follow this Question
Related Questions
How to deactivate gameObjects instead of destroying them ? 1 Answer
What happens to the code of the Start/Awake function when I deactivate a gameobject? 1 Answer
Why does the Unity HingeJoint2D not work when enabled during play? 0 Answers
Activating things- What on earth am I doing wrong??? 2 Answers