Problem in accessing a script variable from another variable....

Object reference not set to an instance of an object movment.Update ()

I have this error msg when im trying to use the variables from the first class into the second .

public class movment : MonoBehaviour { void Update () { MainCode child1 = GetComponent(); print( child1 .transform.position.ToString()); } }

public class MainCode : MonoBehaviour { void Update () { } }

When you paste code, please use the Code Sample button in the editor to make sure it gets formatted properly.

In your code, GetComponent is not given an argument. Unity has no chance to know what component you're requesting.

If MainCode is the name of the script applied to a GameObject, that is the child of a GameObject to which the script movment is applied, then you can access it through,

transform.FindChild("[NameOfMainCode's GameObject]").GetComponent<MainCode>();

Try to adapt this sample JavaScript in C #:

ScriptName.VariableName;