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

Hi ,
How i can access my variables via multiple classes but in the same scene,
here is my example :

sing UnityEngine;
using System.Collections;

public class MainCode : MonoBehaviour {
public Vector3 point1;

void Update () {

hit = new RaycastHit() ;
ray =Camera.main.ScreenPointToRay ( (Input.mousePosition));
if (Physics.Raycast(ray, out hit, 7000))
{
point1 = hit.point ;
}


public class movment : MainCode {
void Update () {
if (Input.GetMouseButtonDown(0) )
{

// here i need to print my hit.point where it is in MainCode class

}}}
:face_with_spiral_eyes::face_with_spiral_eyes::face_with_spiral_eyes::face_with_spiral_eyes::face_with_spiral_eyes::face_with_spiral_eyes::face_with_spiral_eyes::face_with_spiral_eyes:

You need to get a reference to the object with the other script and then use GetComponent to access the script component itself (there is some sample code for doing this on the manual page).

I use Unity for my classes on Game Programming, and this is the most asked question. I’m creating a FAQ with the all the most asked questions and important hints about Unity. Question 2 may help you. (It’s in C#) http://www.mindgear.cc/unityfaq/

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 () {
}
}