Using GetComponet on a child object

Hi

this is my hierarchy http://img.skitch.com/20101201-p7ntm3hue1uqa6p7ur897s41rb.jpg

I am to get a referance to the score value gameobject.

here is my script so far

var score : SpriteText;

function Start() {
    //score = camera.main.GetComponentInChildren(SpriteText);
    var maincamera = transform.Find(camera.main+"Score");   
    Debug.Log(maincamera.name);
    //score = maincamera.GetComponentInChildren(SpriteText);
    StartFade();
    kill();
    audio.Play();
}

but score doe'st seam to get reference to it

Thanks

The main camera line looks like it is the wrong one

var maincamera = Camera.main.transform.Find("Score");

Try stick to Camera.main instead of camera.main - camera.main is a weird javascript only thing which is very likely slower

Your use of Transform.Find is incorrect. Why are you passing camera.main(A Camera object) + "Score"?

With the hierarchy depicted, you probably want something like:

var scoreTransform : Transform = transform.Find("Score");

or

var scoreTransform : Transform = Camera.main.transform.Find("Score");

camera.main returns the main camera of the camera attached to the current object. If the current object does not have a camera attached, camera returns null and camera.main will give you a NullReferenceException.