Effect Won't Respond to Trigger when Child of an Object

Basically I want the lights/torches in a room to light up when the player enters the room.
If I have just a standard flame(particle effect) in the room then the following code works fine
(flame appears on enter and disappears on exit)

#pragma strict

var flame : GameObject;

function Start ()
{
    flame.SetActive(false);
}

function OnTriggerEnter()
{
    flame.SetActive(true);
}

function OnTriggerExit()
{
    flame.SetActive(false);
}

Moving on I now have a nice model of a medieval torch with the flame effect attached but I get nothing when entering or exiting the trigger area ?
I found some info that said its because SetActive doesn’t work with Objects/Transforms so I tried using…

#pragma strict

var torch : GameObject;

function Start ()
{
    torch.enabled = false;
}

function OnTriggerEnter()
{
    torch.enabled = true;
}

function OnTrigerExit()
{
    torch.enabled = false;
}

‘torch’ being the name of the parent object, but this just gave an error message.

Any ideas please guys?

It helps if you post the error message.

Assets/Scripts/Effects Proximity.js(7,15): BCE0019: ‘enabled’ is not a member of ‘UnityEngine.GameObject’.
Assets/Scripts/Effects Proximity.js(12,15): BCE0019: ‘enabled’ is not a member of ‘UnityEngine.GameObject’.
Assets/Scripts/Effects Proximity.js(17,15): BCE0019: ‘enabled’ is not a member of ‘UnityEngine.GameObject’.

Use SetActive instead.

torch.SetActive(true);
1 Like

OK, this is what I have so far and technically it’s working fine -

#pragma strict

var torch : GameObject;

function Start ()
{
    torch.SetActive(false);
}

function OnTriggerEnter()
{
    torch.SetActive(true);
}

function OnTriggerExit()
{
    torch.SetActive(false);
}

However it only works on objects/components I drag directly from the hierarchy and not on anything I choose from the prefabs list?