- Home /
Question by
jimmyismike · Aug 15, 2011 at 01:38 PM ·
togglezoom
Toggle zoom
Excuse my noob. How i toggle this zoom script?
var fov = 55;
function Update()
{
if (Input.GetKeyDown("mouse 1"))
fov = 5;
if (Input.GetKeyUp("mouse 1"))
fov = 55;
if (Camera.main.fieldOfView < fov)
Camera.main.fieldOfView++;
if (Camera.main.fieldOfView > fov)
Camera.main.fieldOfView--;
}
Comment
Best Answer
Answer by DaveA · Aug 15, 2011 at 04:04 PM
I assume this works as-is, but you want to have it zoom in on the first mouse press and zoom out on the second mouse press? If not please edit the question.
Untested
var zoomed = false;
var minfov = 5;
var maxfov = 55;
function Update()
{
if (Input.GetKeyDown("mouse 1"))
zoomed = !zoomed;
if (!zoomed && Camera.main.fieldOfView < maxfov)
Camera.main.fieldOfView++;
if (zoomed && Camera.main.fieldOfView > minfov)
Camera.main.fieldOfView--;
}
Your answer
![](https://koobas.hobune.stream/wayback/20220612181128im_/https://answers.unity.com/themes/thub/images/avi.jpg)
Follow this Question
Related Questions
Sniper zooming (toggle) 2 Answers
GUI texture ? help please 0 Answers
Changing zoom speed? 1 Answer
Camera Toggle script 1 Answer
Crouch Script Help 1 Answer