Gets a variable from a class sttached to an object, in this example we get it using a collider.
void OnCollisionEnter(Collision col)
{
if (col.gameObject != null && col.gameObject.GetComponent<variableFromClass>() != null)
{
Debug.Log(col.gameObject.GetComponent<variableFromClass>().variableName);
}
}