I upgraded to unity 4.0 and I get a lot of warnings and possibly from that, mac appstore validation fails. I am activating/deacivating a couple of game objects with this
#pragma strict
public var blackScreen : GameObject;
var lightSwitchObject : GameObject;
var lightOnSound : AudioClip;
var lightOffSound : AudioClip;
var LIGHTON : GameObject;
var LIGHTOFF : GameObject;
function Start(){
blackScreen.animation.Play("Alpha0");
LIGHTON.SetActiveRecursively (true);
LIGHTOFF.SetActiveRecursively (false);
}
function fadeIn(){
blackScreen.animation.Play("Alpha0");
}
function fadeOut(){
blackScreen.animation.Play("Alpha255");
}
function DarkRoom()
{
fadeIn();
lightSwitchObject.active = false;
audio.PlayOneShot(lightOnSound);
LIGHTON.SetActiveRecursively (true);
LIGHTOFF.SetActiveRecursively (false);
}
function LightRoom()
{
fadeOut();
lightSwitchObject.active = true;
audio.PlayOneShot(lightOffSound);
LIGHTON.SetActiveRecursively (false);
LIGHTOFF.SetActiveRecursively (true);
}
function DarkRoomDummy()
{
lightSwitchObject.active = false;
}
function LightRoomDummy()
{
lightSwitchObject.active = true;
}
and the warning is like this:
Assets/Scripts/NewCameraFadeBlack.js(28,27): BCW0012: WARNING: ‘UnityEngine.GameObject.active’ is obsolete. GameObject.active is obsolete. Use GameObject.SetActive(), GameObject.activeSelf or GameObject.activeInHierarchy.
EDIT
for this particular case I can probably use instantiate and destroy and forget about active inactive for now. The problem is that I cannot understand (read the docs) for the life of me how to check if a child object is active.
private function HasChildren(obj:Transform)
{
var active:int = 0;
for (var _child:Transform in obj)
{
if (_child.gameObject.active == true)
active++;
}
return (active > 0);
}
if (_child.gameObject.active == true) - I need to check if the current set of targets are active (they are parented to a game object used to activate that particular set).