I’ve searched around on the forums and online, and this would seem to be a simple question from what I found. The best method I found for controlling visibility of GameObjects was setting
myObject.renderer.enabled = false; //makes object invisible
myObject.renderer.enabled = true; //makes object visible
This method actually works most of the time for me. However, in my game, I use a Reset method (that I created), which is called by a BroadcastMessage sent when the player dies. This Reset method is supposed to reset all objects in the level. It is getting called, but the contents of it are not working. It is important to note that the GameObject I am using has an attached animation as well, which I attempt to Rewind in this method as well to no avail. Here is the specific code for the Collectable class I have:
protected bool Reset()
{
animObject.renderer.enabled = true;
if (animObject && animObject.animation.GetClip("collect"))
animObject.animation.Rewind("collect");
if (this.animation && this.animation.GetClip("collect"))
this.animation.Rewind("collect");
return true;
}
Using Debug statements I ascertained that the method IS getting called, and the renderer.enabled variable is getting set to true. However, when I pause the game, the mesh renderer is disabled in the editor! And regardless of whether I pause or not, the GameObject I was trying to set visible again never shows up, but IS in the right spot and is collidable.
It perplexed me further when I found that setting the renderer.enabled variable worked just fine in other methods, but whenever I called it from this Reset method it didn’t work. None of the other GameObjects being reset with the BroadcastMessage affect these collectables that should be getting reset.
Am I doing something wildly wrong?