active.InHierarchy not working

Hi - I have a light which I only want to be seen by one camera, but as culling masks don’t work, I thought I’d set this light to active when the player sets the camera to active.

But I can’t work out why this script doesn’t work - I can see the correct camera is active in the hierarchy, but although no errors are thrown - the light isn’t set to active.

Any ideas why?

public var cameraC4N :GameObject;

var spotLight : GameObject;


function Start () {

spotLight.active = false;

}

function Update () {

 if(cameraC4N.activeInHierarchy == true)

{

spotLight.active = true;

}

}

All the best, Laurien

Do you have this script attatched to a GameObject which happens to be disabled? Or is the script iteself not enabled? If so, then the Update is not called, and your code will never execute. Because I believe there is nothing wrong with the code itself, it works when I try it.