Generic script for enabling 'zones'

I have certain zones almost like houses that can be explored on my FPS map. With these disabled my FPS is great . What I want to do is set these zones as ‘inactive’ untill triggered.

The code I’m using looks like:

var myplayer:GameObject;

function Start() {
{
var ZoneD = GameObject.FindWithTag(“ZoneDed”);
ZoneDed.SetActiveRecursively(false);
}

function OnTriggerEnter(mplayer:Collider)
{
var ZoneD = GameObject.FindWithTag(“ZoneDed”);
ZoneDed.SetActiveRecursively(true);
}

function OnTriggerExit(mplayer:Collider)
{
var ZoneD = GameObject.FindWithTag(“ZoneDed”);
ZoneDed.SetActiveRecursively(false);
}

Essentially it doesnt work, and I’m not sure why. If I do the reverse, it works - what I mean with that is if I switch the above script’s true to false and visa versa it works, but it never comes on again either way.

So essentially it ‘inactivates’ my object but never ‘activates’ them again.

Thx
nOrb

Your problem is that the engine can’t find objects which are disabled. Save a reference to the objects and use those references to enable them instead of finding them every time.

Yeah thx, it took me a while to click, I just made them public vars