Spawn on a timer

I have code that will spawn what I want on screen but there are two things I need to fix. One I need to spawn based on a timer after you hold the mouse down and have it spawn in a certain location. Can help will be useful, Thank you

var crystal : Transform;

function Update ()

{

var mousex = Input.mousePosition.x;

var mousey = Input.mousePosition.y;

var ray = camera.main.ScreenPointToRay (Vector3(mousex,mousey,0));

if ( Input.GetMouseButtonDown(0))

{

var crate = Instantiate(crystal, ray.origin, Quaternion.identity);

}

}

private float timer = 0.0f;
public float timeToHoldDownMouseBeforeSpawn = 3.0f;
.
.
.
.
if ( Input.GetMouseButton(0))
timer+= time.deltaTime;
if( Input.GetMouseButtonUp(0))
timer = 0;
if(timer >= timeToHoldDownMouseBeforeSpawn)
{
timer = 0.0f;
var crate = Instantiate(crystal, ray.origin, Quaternion.identity);
}