Finding parent class variable from class variable?

If I have a class. Can I find a variable made with that class from a dotted (sub) variable somehow?

class Car {
body:GameObject;
color:String;
}

mycar = new Car()
mycar.body = Instantiate some Prefab.
mycar.body.name=“RacingCar”

Let’s say I want to find it by name…
thecar=GameObject.Find(“RacingCar”);
will give me the mycar.body
How do I get from this to mycar?

Thanks,

Dan

If you want something to be attached to a gameobject and don’t want to keep track of the mycar variable yourself it might be worthwhile to use the Car script as a component and then add that to mycar. Make Car as a separate script and then use AddComponent and GetComponent.

//Instantiate some prefab 
prefab.AddComponent(Car);
prefab.name = "RacingCar";

// then if you want to get the component
GameObject theCar = GameObject.Find("RacingCar");
var carScript : Car = theCar.GetComponent(Car);

Check out the Component.GetComponent part of the manual for more details.