GetComponent To Read Up Hierarchy?

Hello,

I have a game object called MissileLauncher, within that I have a child called Missile. The Missile has a script on it that needs to change a variable in a script attached to the MissileLauncher.

I try to use GetComponent, but I always seem to get a null when getting a component up the hierarchy (on the parent). Is there a way to do this? I've been using all the examples that the Scripting API gives, and I can never do it?!

Okay, here is my layout:

MissileLauncher (Parent), contains variable:

var timeInterval : float = 2;

Missile (Child), needs to talk to 'timeInterval':

getMissileLauncher = gameObject.GetComponent("MissileLauncher");
getMissileLauncher.timeInterval = 5;

Every time I play, I get a null error. Also, I don't want to use statics.

How do I talk upward?? Driving me crazy!

Thanks folks!

Try this:

getMissileLauncher = transform.root.GetComponentInChildren.<MissileLauncher>();

It'll get the MissileLauncher script no matter which parent/sibling it's in.

Alternatively:

getMissileLauncher = transform.parent.GetComponent.<MissileLauncher>();

Will get the script from one parent up.

Or:

var missileLauncher : MissileLauncher;

Declared at the top of your file, it'll let you drag in the missile launcher at editor time, so you don't need to getcomponent all the time