Reference specific variable from a specific gameObject?

ok so say i have a grid of like 100 cubes and i have a script that gets the object next to the previous grid that is then assigned to a variable. i then have a script that assigns a cube that is under my mouse to a variable how would i get the first variable from that certain cube? here are some scripts to help it make more sense


var hit : RaycastHit;
    var ray = Camera.main.ScreenPointToRay (Input.mousePosition);
      if ( Physics.Raycast( ray, hit, 100 ) ){

        if (hit.collider.CompareTag("gridFloor")){
// gridPoint is the cube under mouse i was talking about!
           gridPoint = hit.collider.gameObject;



for(var i : int = 0; i < findTotalRows.gridX; i++)
	for (var j : int = 0; j < findTotalRows.gridY; j++)
		if([i,j].name ==
			myX = i;
			myY = j;
xNext = myX + 1;
yNext = myY + 1;
xBack = myX - 1;
yBack = myY - 1;

tileUp =[myX,yNext];
tileDown =[myX,yBack];
tileLeft =[xBack,myY];

tileRight =[xNext,myY]; 

these cubes are already put in an array called map[,] by the way

IMPORTANT all variables are showing up in inspector which means they are getting assigned correctly!!!

Based on what I think I understand about your issue, I would recommend this (again):

  • Attach the script named GuiStart to an object in your scene named FunkyObject

  • Add the following to the top of AIWalk.js:

    public var guiStartScript : GuiStart;</pre></code>
    <li><p>Attach AIWalk to some object in your scene</p></li>
    <li><p>Select the item AIWalk is attached to by left-clicking it in the Hierarchy</p></li>
    <li><p>Look at the Inspecter and observe a slot named <em>Gui Start Script</em></p></li>
    <li><p>Drag <em>FunkyObject</em> (the item we attached GuiStart to) onto the slot named <em>Gui Start Script</em> in the Inspector</p></li>
    <p>You will now be able to access GuiStart's variables and functions in the script named AIWalk.js like this:</p>
    <pre><code>if ( guiStartScript != null ) {

    printInfo is a hypothetical name for a function that would "do stuff" to gridPoint.tileRight...

    By adding the above line to your AIWalk script, you say this to the compiler:

      This script contains a reference to another object that has a GuiStart script attached to it. I can now do whatever I want with the functions and variables associated with that object's GuiStart script.</ul

Ha ha ha… looking back at these old questions gives me a good laugh at how far i have come! still working at unity3D and loving every minute of it thanks to great tools like this and the awesome community surrounding it!