Accessing variables of objects in scene and not in assets

If I wanted to grab a variable from an item in the scene would I use

var variable;
var gameObject : Transform;
variable = gameObject.GetComponent(scriptName).variableName; 

or would I use something else?

I wouldn’t use gameObject as a variable name, since it’s already a component of the object your script is attached to. I’m guessing you just did that for example’s sake, though. So yes, you’re on the right track, GetComponent is definitely the way to go. Check out the Unity Script Reference for more information.