My variable doesn't update real-time?

Hello,

when I update the variable distance in play mode it doesn’t update in real-time?

#pragma strict

var Distance: float; //Value determind how much the object is away from the mouse.


private var hardX: float=Distance; 
private var hardY: float=Distance;



private var diff =Vector3(hardX,hardY,0);



var followingObject : Transform; //The object that's gonna follow the mouse.


 
function Update ()

{

  var v3T = Vector3(Input.mousePosition.x+diff.x, Input.mousePosition.y+diff.y, 106.6723);
  
  v3T = Camera.main.ScreenToWorldPoint (v3T);
  
  followingObject.position = v3T;
  
if (Input.GetKeyDown('space'))
{

Distance +=100;

}
  
}

Thanks.

You cannot do calculations outside of functions.

#pragma strict

var Distance: float; // Value determind how much the object is away from the mouse.

private var hardX : float; 
private var hardY : float;

private var diff : Vector3;

var followingObject : Transform; // The object that's gonna follow the mouse.

function Update()
{
	hardX = Distance; 
	hardY = Distance;

	diff = Vector3( hardX,hardY,0 );

	var v3T = Vector3( Input.mousePosition.x + diff.x, Input.mousePosition.y + diff.y, 106.6723 );

	v3T = Camera.main.ScreenToWorldPoint( v3T );

	followingObject.position = v3T;

	if ( Input.GetKeyDown('space') )
	{
		Distance += 100;
	}
}

Set the transform. If you don’t use Distance, Distance does not get used.