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.
You want something like this:
Camera.main.fieldOfView = 10;
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;
fov = 10;
fov = 90;
if (Camera.main.fieldOfView < fov)
if (Camera.main.fieldOfView > fov)
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
You need to make a nested if statment if you know what that means.
Hey you can use the following script if you want to zoom in 2d . this is pinch to zoom.
float zoomSpeed = 8.5f;
float minZoomOut = 1;
float maxZoomOut = 15;
if (Input.touchCount == 2 && (Input.GetTouch(0).phase == TouchPhase.Began || Input.GetTouch(1).phase == TouchPhase.Began))
// calibrate the distance value;
previousDistance = Vector2.Distance(Input.GetTouch(0).position, Input.GetTouch(1).position);
else if (Input.touchCount == 2 && (Input.GetTouch(0).phase == TouchPhase.Moved || Input.GetTouch(1).phase == TouchPhase.Moved))
Vector2 touch1 = Input.GetTouch(0).position;
Vector2 touch2 = Input.GetTouch(1).position;
distance = Vector2.Distance(touch1, touch2);
//camera based on pinch/zoom
float PinchAmount = (previousDistance - distance) * zoomSpeed * Time.deltaTime;
//Debug.Log("PinchAmount Val is "+ PinchAmount);
Camera.main.orthographicSize = Mathf.Clamp(Camera.main.orthographicSize + (PinchAmount * 0.05f), minZoomOut, maxZoomOut);
Camera.main.transform.Translate(0, 0, PinchAmount);
previousDistance = distance;