Hello all! I’m very new to actual scripting so please bear with me. I want to write a script and it should work like this, but it doesn’t.
var activated: MonoBehaviour[] ;
function OnTriggerEnter (other: Collider) {
for(var go in activated)
{
go.enabled = false;
}
}
What I want to do is to put this script on a trigger. I put a bunch of gameobjects in the editor and deactivate them. Then drag and drop those objects into the slots from the monobehavior in the script. (ex: Size = 2, then drag/drop a gameobject into the 2 slots). What I’m trying to do is that when the player walks through the trigger, the objects become active. As it is now, when the player walks through the trigger, I get the error message “Object reference not set to an instance of an object”. I tried a couple variations of the script but this seemed to be the one that got the closest. What am I doing wrong? I’d really appreciate any help at all 
That should be “var activated : GameObject[ ];” and the “go.enabled” line should be either “go.renderer.enabled” or “go.active”.
–Eric
Eric, thanks for the response!
That seems to have worked…partially. I’m testing it out in the FPS Tutorial. I assigned one of the robots to be one of the objects that gets activated. When I walk through the trigger and the robot is already deactivated, nothing happens (but no errors so that’s good). I tried it with the robot already active and when the player walks through the trigger, he suddenly freezes on the spot and doesn’t do anything (he doesn’t disappear though).
Here’s what the code looks like now
var activated: GameObject[] ;
function OnTriggerEnter (other: Collider) {
for(var go in activated)
{
go.active= false;
}
}
I checked to see what happens in the inspector. When the robot freezes, the checkbox in the inspector does get unchecked and the player can even walk through the robot which means the collider has been turned off, however the mesh remains visible. When the robot is already off though, nothing happens at all, not even in the inspector.
Try having a boolean variable in the robot script that activates/deactivates it, and also an Activate function:-
var isAwake: boolean;
function Update() {
if (isAwake) {
...do something...
}
}
function Activate() {
isAwake = true;
}
Then use GameObject.SendMessage in the OnTriggerEnter of the trigger script to call Activate on all the robots:-
var activated: GameObject[] ;
function OnTriggerEnter (other: Collider) {
for(var go in activated)
{
SendMessage(go, "Activate");
}
}