- Home /
SetActive() not working
hi
i'm using unity 3.5
i want active an object in script
how can i do this?
i use SetActive method but it's got error
error text :
Assets/Scripts/GameManager.cs(39,34): error CS1061: Type
UnityEngine.GameObject' does not contain a definition for
SetActive' and no extension methodSetActive' of type
UnityEngine.GameObject' could be found (are you missing a using directive or an assembly reference?)
tnx 4 adv
Answer by robhuhn · Dec 04, 2013 at 10:12 AM
GameObject.SetActive() was introduced in Unity 4. In Unity 3.5 it was GameObject.active and GameObject.SetActiveRecursively().
Sources: http://docs.unity3d.com/Documentation/Manual/UpgradeGuide3540.html http://answers.unity3d.com/questions/324130/unity4-active-replacement.html http://answers.unity3d.com/questions/329394/unity-4-gameobjectactive-equivalent.html
i m using unity 4.2 but still neither gameObject.setActive nor gameObject.active are working plzz can suggest the solution
Answer by burnill · Dec 04, 2013 at 10:03 AM
GameObject.SetActive() needs to have a lowercase G at the start or replace GameObject with a reference to a game object for example:
var explosion : GameObject;
function Awake ()
{
explosion.SetActive(false);
}
OR
// Deactivates the game object.
gameObject.SetActive (false);