GameObject won't turn back on

i have this script

#pragma strict

var target : Transform;

function Start () 
{
	
}

function Update () 
{
	if(Physics.Linecast(transform.position, target.position))
	{
		gameObject.SetActive(false);
	}	

	if(!Physics.Linecast(transform.position, target.position))
	{
		gameObject.SetActive(true);
	}
	transform.LookAt(target);
}

it’s attached to a directional light which is the child of a local star, siblings to other objects such as particle systems and a point light, and the target is the u.s.s. voyager. when the ship goes around the planet, the light deactivates, giving the illusion of the sun being occluded by the planet, but it won’t turn back on after voyager emerges from the other side of the planet. any ideas?

You are deactivating the main gameobject, this will disable all the mono-behaviour functions on the game object including the update function in your script. As update function is not running, the physics linecast will also not work.

Solution : Dont disable the gameobject, instead store a refference to the gameobject that you want to disable and keep the script on its parent.

e.g.

Parent [script]

→ light (child of parent)

script will store the refference of the light game object.