Accessing component

Hi
Im a bit stuck here. Trying to turn on and off a component via trigger:

var otherscript:GameObject;
var otherscript1:GameObject;
function OnTriggerEnter () {
    otherScript = GetComponent(SmoothLookAt);
    otherScript.active=true;
     otherScript1 = GetComponent(SmoothLookAt);
    otherScript1.active=true;
}
function OnTriggerExit () {
    otherScript = GetComponent(SmoothLookAt);
    otherScript.active=false;
      otherScript1 = GetComponent(SmoothLookAt);
    otherScript1.active=false;
}

Its the null ref exception:Object ref not set to an instance…Is it because Im accessing the same (SmoothLookAt )Script on two GO’s…?

Thank you
AC

It’s generally a bad idea to have more than one instance of a script attached to the same GO. Are you using the trigger to switch back and forth between different settings? In this case, it might be a good idea to build that functionality into the SmoothLookAt script.

They are not in the same object, its one script attached to two different objects.

var otherscript:GameObject;
var otherscript1:GameObject;
function OnTriggerEnter () {
    otherScript = GetComponent(SmoothLookAt);
    otherScript.active=true;
     otherScript1 = GetComponent(SmoothLookAt);
    otherScript1.active=true;
}
function OnTriggerExit () {
    otherScript = GetComponent(SmoothLookAt);
    otherScript.active=false;
      otherScript1 = GetComponent(SmoothLookAt);
    otherScript1.active=false;
}

GetComponent get the component of some object, if you use GetComponent alone, it will search in the object this script is attached to.

On the other hand, GetComponent returns a Component, base clase for all components (including SmoothLookAt) and your variables are declared as GameObject.

You should have something like this to (de)activate components

var object : GameObject; // setted in the inspector to be the object in which lays the component to be (de)activated

private var script : ComponentName;

function Awake ()
{
   script = object.GetComponent (ComponentName); // cache the component
}

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

function OnTriggerExit ()
{
   script.enabled = false;
}

.ORG

Cheers for the heads up guys, you can see Omars version of the script in action here:
http://forum.unity3d.com/viewtopic.php?p=44361#44361

The eyeballs. I will try something similar with the whole head one day…
AC