I have a skinned mesh that i am trying to make inactive (and invisble).
I am setting the GameObject.active to false but it’s still visible in the game and editor windows (it is greyed out in the hierarchy though).
// Update is called once per frame
void Update () {
// Loop through Explosion Array and set initial values
for (int i = 0; i < explosionArray.Count; i++)
{
GameObject workingEXPLOSION2 = (GameObject)explosionArray[i];
ExplosionData workingEXPLOSIONDATA2 = workingEXPLOSION2.GetComponent("ExplosionData") as ExplosionData;
if ( !workingEXPLOSIONDATA2.ExplosionAlive){
Debug.Log("enemy inactive");
workingEXPLOSION2.active = false;
}
else{
Debug.Log("enemy active");
workingEXPLOSION2.active = true;
}
}
}
the code seems to be working fine as the correct Debug output is showing in the console (and like i said, the objects are greyed out in the editor). Problem is, i can still see the blasted thing in the gae view! LOL!
I guessing there is something wrong with the model or prefab??? any ideas??? I’ve never come across this issue before and active as always worked fine, that said, this is the first ‘skinned mesh’ i’ve used it on.
As I said previously I have never had this problem before so I am assuming that it is due to the Object being a skinned mesh with 17 bones being present as well as the actual mesh (g0).
Is this a correct assumption?
Therefore, is this an intensive task to search through all the object’s children each update? Let’s just say I know the renderer is on the mesh object, g0, within the mesh, is there a way to alter the properties of this without searching through all children?
I use SetActiveRecursively. Make an empty gameObject the parent of your mesh/armature, which you probably already have. Disable your mesh/armature using
function Start () {
gameObject.SetActiveRecursively(false);
//this will deactivate your mesh and all its children
}
then when you need to enable it use
yourParentObject = gameObject.FindWithTag ("yourParentObject");
yourParentObject.SetActiveRecursively(true);
//this will activate your mesh and all its children.