Using GetComponet on a child object


this is my hierarchy

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");   
    //score = maincamera.GetComponentInChildren(SpriteText);

but score doe'st seam to get reference to it


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");


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.