This script let you zoom in and out and orbit around an object (normally the player) when pressing the mouse Wheel. In the inspector we have to drag the Player to the correspont slot.
using UnityEngine;using System.Collections;public class TopDownCamera : MonoBehaviour{ public Transform target; private bool orbiting, starting; [System.Serializable] public class PositionSettings { public float distanceFromTarget = -10; public bool allowZoom = true; public float zoomSmooth = 2; public float zoomStep = 30; public float maxZoom = -5; public float minZoom = -40; public bool smoothFollow = true; public float smooth = 0.05f; [HideInInspector] public float newDistance = -10; //used for smooth zooming - gives us a destination zoom } [System.Serializable] public class OrbitSettings { public float xRotation = -45; public float yRotation = -180; public bool allowOrbit = true; public float yOrbitSmooth = 0.5f; } [System.Serializable] public class InputSettings { public string MOUSE_ORBIT = "MouseOrbit"; //key entry created by us in Edit->Project Settings->Input public string ZOOM = "Mouse ScrollWheel"; // key entry that Unity provides by default } public PositionSettings posSet = new PositionSettings(); public OrbitSettings orbit = new OrbitSettings(); public InputSettings input = new InputSettings(); Vector3 destination = Vector3.zero; Vector3 camVelocity = Vector3.zero; Vector3 currentMousePosition = Vector3.zero; Vector3 previousMousePosition = Vector3.zero; float mouseOrbitInput, zoomInput; void Start() { starting = true; SetCameraTarget(target); if (target) { MoveToTarget(); } } public void SetCameraTarget (Transform t) { target = t; if (target == null) { Debug.LogError("Your camera needs a target"); } } void GetInput() { mouseOrbitInput = Input.GetAxisRaw(input.MOUSE_ORBIT); zoomInput = Input.GetAxisRaw(input.ZOOM); } void Update() { GetInput(); if (posSet.allowZoom) { ZoomInOnTarget(); } } void FixedUpdate() { if (target) { MoveToTarget(); LookAtTarget(); MouseOrbitTarget(); } } void MoveToTarget() { destination = target.position; destination += Quaternion.Euler(orbit.xRotation, orbit.yRotation, 0) * -Vector3.forward * posSet.distanceFromTarget; if (posSet.smoothFollow) { transform.position = Vector3.SmoothDamp(transform.position, destination, ref camVelocity, posSet.smooth); } else transform.position = destination; } void LookAtTarget() { // getting our camera to look at the target at all times Quaternion targetRotation = Quaternion.LookRotation(target.position - transform.position); transform.rotation = targetRotation; } void MouseOrbitTarget() { // getting the camera to orbit around our character previousMousePosition = currentMousePosition; currentMousePosition = Input.mousePosition; if (mouseOrbitInput > 0) { Cursor.visible = false; orbiting = true; orbit.yRotation += (currentMousePosition.x - previousMousePosition.x) * orbit.yOrbitSmooth; orbit.xRotation += currentMousePosition.y - previousMousePosition.y; if (orbit.xRotation > -15f) orbit.xRotation = -15f; else if (orbit.xRotation < -70f) orbit.xRotation = -70f; } else { // During orbiting the cursor is locked and invisible. if (orbiting) { Cursor.lockState = CursorLockMode.Locked; orbiting = false; } // After orbiting the cursor is unlocked and visible Cursor.lockState = CursorLockMode.None; Cursor.visible = true; } } void ZoomInOnTarget() { // set the zoom starting distance if (starting) { posSet.newDistance = posSet.distanceFromTarget; starting = false; } else { posSet.newDistance += posSet.zoomStep * zoomInput; posSet.distanceFromTarget = Mathf.Lerp(posSet.distanceFromTarget, posSet.newDistance, posSet.zoomSmooth * Time.deltaTime); if (posSet.distanceFromTarget > posSet.maxZoom) { posSet.distanceFromTarget = posSet.maxZoom; posSet.newDistance = posSet.maxZoom; } if (posSet.distanceFromTarget < posSet.minZoom) { posSet.distanceFromTarget = posSet.minZoom; posSet.newDistance = posSet.minZoom; } } }}This is the custom input key MouseOrbit that we created for the orbiting effect in the Input Manager. "mouse 2" refers to the mouse wheel button press: