Using a member variable from one function in another

I've never actually needed to do this until now and I can't understand how.

I'm trying to get the `hit.normal` variable from one function to use in another function within the same script.

function spawn() {
    //Im trying to use the hit.normal from GetPointOnMesh function
    var startRot = Quaternion.LookRotation(hit.normal);
    var fissurePrefs = Instantiate(fissure, randomPoint.point, startRot);
} 

function GetPointOnMesh() : RaycastHit{
    var hit : RaycastHit;
    Physics.Raycast (ray, hit, length*2);
    return hit;
}

this is more of a general programming question. Its a matter of scoping. Variables created within a function cannot be accessed outside of the function. So to have it be able to be accessed from outside the function, just initialize it outside the function, like so:

var hit:RaycastHit;
function spawn(){...}
function GetPointOnMesh(){...

now the problem here is, you will have to check if hit is null or not before doing your LookRotation. Hope this helps you out.

Variables declared inside a function are local to that function only. Since you're returning the RaycastHit from GetPointOnMesh, just call that function instead of using "hit" in your spawn function.

Kennypu explained the matter of scoping, but you might want to use this approach, I did not test this specific example, but it should work:

function GetPointOnMesh():RaycastHit{
    var hit : RaycastHit;
    Physics.Raycast (ray, hit, length*2);
    spawn(hit.normal);
}

function spawn(thePoint){
    var startRot = Quaternion.LookRotation(thePoint);
    var fissurePrefs = Instantiate(fissure, randomPoint.point, startRot);
}

Simply send the hit.normal as a parameter to the next function.