Hi everyone, I have a GameObject Array that I would like to have it's SetActive set to false.But how I do that since arrays don't have a definition for SetActive?
Answer by flamy
Jun 29, 2013 at 07:30 PM
foreach(GameObject _obj in gameObjectArray)
there is no direct method to do that. This is the only way.
Correct. You can access each gameObject in the array with a foreach statement. This statement shown disables ALL instances of _obj in the array. +1
how can you reenable the deactivated items ? _obj.SetActive(true); does not seem to work
@trelobyte, you should post this as a new question with a link to this one. Anyway, SetActive(true) is the right way to reactivate the object - but be aware that in Unity 4 the object will remain deactivated if its parent is inactive (see GameObject.SetActive)
Answer by newmaker
Mar 09 at 08:27 AM
@trelobyte, if you have OnTriggerEnter, try copy the same code in this function into the OnTriggerExit function and then set it to set.Active(false); this should work.
Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.
The best place to ask and answer questions about development with Unity.
To help users navigate the site we have posted a site navigation guide.
If you are a new user to Unity Answers, check out our FAQ for more information.
Make sure to check out our Knowledge Base for commonly asked Unity questions.
If you are a moderator, see our Moderator Guidelines page.
We are making improvements to UA, see the list of changes.
Answers and Comments
21 People are following this question.
C# Find Which Axes Gameobject is on
C# Array of OtherArray's Meshes
C# Gameobject Rigidbody Mouse Collision
C# Children and SubChildren Null Reference Exception
C# Child GameObject Disabled Script SetActive(false)