Accessing Instantiated Primitive from A Seperate Class

Question pretty much says it all, guys. Say I have a class named Tim and a class named Bob.

In class Tim, the GameObject of Tim is instantiated, and let’s say there’s a getter function:

GameObject Tim;

void Start() {
     Tim = GameObject.CreatePrimitive(PrimitiveType.Sphere);
     Tim.renderer.material = TimMaterial;
     setTimPosition(new Vector3(0f, 600f, 1550f));
}

public GameObject grabTim {
     get { return Tim; }
}

Now in class Bob, Bob needs to know the location of Tim to setup his initial position. So let’s say in class Bob, I create a new Tim object by doing:

Tim timObject = ###;

What actual code would replace the “###” to assign a value to the timObject variable? I know I need to assign the instaniated gameObject, but how?. In order to retrieve the position of Tim, I figured I could try something like:

void Update() {
         if (Input.GetKeyDown(KeyCode.Space)) {
              Debug.Log("Tim's position: " + timObject.grabTim.transform.position);
         }
    }

But I can’t access anything within the Tim class because the timObject variable is returning null because it isn’t being assigned an actual value.

Well, if you do not have any classes or objects with a reference to the Tim object then you would have to search for Tim instead:

Tim timObject = GameObject.FindObjectOfType(typeof(Tim)) as Tim;

This works if you have only one Tim in your scene, if you have multiple objects of Tim then the function above will return the first one it finds.