Could someone to write me a script to make a gun zoom in when you hold down Z then when you release Z it zooms back out.What I need is a machine gun zoom,the kind on halo.
Plus, I need to know what kind of script I would write it in and what object the script would be in.
I would really appreciate any help I can get,Thanks.
function Update()
{
if (Input.GetKeyDown("z"))
Camera.main.fieldOfView = 10;
if (Input.GetKeyUp("z"))
Camera.main.fieldOfView = 90;
}
If you want that zoom effect to interpolate over, say, a littel over a second, that's also easy
var fov = 90;
function Update()
{
if (Input.GetKeyDown("z"))
fov = 10;
if (Input.GetKeyUp("z"))
fov = 90;
if (Camera.main.fieldOfView < fov)
Camera.main.fieldOfView++;
if (Camera.main.fieldOfView > fov)
Camera.main.fieldOfView--;
}
There's ways to adjust the speed, let me know if you need that.
Not a spoon feed community, but if you ask more of a specific question people are more than willing to help. Ex for when you press z
if(Input.GetKeyDown("z")
{
//zoom camera
}
You need to make a nested if statment if you know what that means.