I have a top down shooter game where if you click/touch the screen the camera zooms in and follows your mouse/touch. It then goes back to it’s original position upon release. I have the Vector3.Lerp inside of LateUpdate but would like to add a delay so that the camera isn’t zooming in and out on semi-automatic fire style shots (just tapping a random enemy here and there). Basically if you hold down for more than half a second then it will zoom.
Is there a way to add a delay to either Vector3.Lerp or possibly call the action outside of LateUpdate. Or could I somehow say “if(Input.GetMouseButton(0) && holdDownTime is > .5f){ do action}”?
Here is What I got:
#pragma strict
var Damping = 5.0;
var Player : Transform;
var Height1 : float;
var Height2 : float;
var Offset : float;
var ViewDistance : float = 5.0;
private var Center : Vector3;
function LateUpdate (){
var mousePos = Input.mousePosition;
mousePos.z = ViewDistance;
var CursorPosition : Vector3 = Camera.main.ScreenToWorldPoint(mousePos);
var PlayerPosition = Player.position;
if(Input.GetMouseButton(0))
{
Center = Vector3((PlayerPosition.x + CursorPosition.x) / 2, PlayerPosition.y, (PlayerPosition.z + CursorPosition.z) / 2);
transform.position = Vector3.Lerp(transform.position, Center + Vector3(0,Height1,Offset), Time.deltaTime * Damping);
}
else//(Input.GetMouseButtonUp)
{
transform.position = Vector3.Lerp(transform.position, Vector3(0,Height2,Offset), Time.deltaTime * Damping);
}
}