- Home /
Question by
diegojose · Sep 08, 2013 at 02:36 PM ·
animationcamerazoomortographic
Ortographic Camera Zoom animation
Hello,
Im trying add animation to my camera zoom with the script below The code works well without animation when i use a number inside the if statement (ex. currentZoom += 1). But when i try to insert the Mathf.SmoothStep function the code doesnt work and the console logs this message
UnityEngine.SendMouseEvents:DoSendMouseEvents(Int32, Int32)" Can anyone help me with this? #pragma strict"Screen position out of view frustum (screen pos 1011.000000, 729.000000) (Camera rect 0 0 1680 880)
var currentZoom = Camera.main.orthographicSize; var duration = 2; private var startTime: float;
function Start() { // Make a note of the time the script started. startTime = Time.time; }
function Update () { var t = (Time.time - startTime) / duration; if (Input.GetKeyUp (KeyCode.KeypadPlus)){ currentZoom = Mathf.SmoothStep(currentZoom, currentZoom - 1, t); } else if (Input.GetKeyUp (KeyCode.KeypadMinus)){ currentZoom = Mathf.SmoothStep(currentZoom, currentZoom + 1, t); } }
Comment
Solved:
#pragma strict
var zoomTarget : float = 0.0;
var newZoom : float = 0;
var zoomSpeed : float = 10;
function Start () {
zoomTarget = Camera.main.orthographicSize;
}
function Update () {
if (Input.Get$$anonymous$$eyDown ($$anonymous$$eyCode.$$anonymous$$eypadPlus)){
zoomTarget = zoomTarget + 4;
Debug.Log(zoomTarget);
} else if (Input.Get$$anonymous$$eyDown ($$anonymous$$eyCode.$$anonymous$$eypad$$anonymous$$inus)){
zoomTarget = zoomTarget - 4;
Debug.Log(zoomTarget);
}
Camera.main.orthographicSize = $$anonymous$$athf.Lerp(Camera.main.orthographicSize, zoomTarget, Time.deltaTime * zoomSpeed);
}