Extending a class

Lets say i had a simple class:

class Test extends UnityEngine.Object{

private var pos : Vector3;

function _get(){

 	pos = GameObject.Find("Main Camera").transform.position;
 	return pos;


function Start () {

    var testClass : Test = new Test(); 

print(testClass);       //prints Null
print(testClass._get());//prints correct value

The problem is that by extending the class - it always gets the value Null, but is actually not Null…

I dont know if “extends UnityEngine.Object” is correct, but it’s the only way i could get “GameObject.Find” to actually work.

Any help would be appreciated.

A look at the Unity3D Documentation could have solved your problem :slight_smile:


etc. are properties of the Component class (UnityEngine.Component). They do not exist in UnityEngine.Object.

If you want to attach your script to an object and access it’s components (transform, rigidbody, colliders are all components) you must derive the script from component too.


Usually all scripts which get attached to the GameObjects are derived from UnityEngine.MonoBehaviour.
All default Unityscripts automatically derive from MonoBehaviour.