Added "inertia" on the basis of the original rotation and scaling.
Using unityengine;using System.collections;public class Cameraobserve:monobehaviour {public Transform targetobj; public float rotatespeed = 100f; public float translatespeed = 10f; public float mindistance = 3f;//Zoom Observe the minimum distance public float maxdistance = 15f;//Zoom Observe the maximum distance public bool Isinertiarot = Fals e;//whether the left button will continue to rotate a few degrees after the public bool Isinertiatra = false;//does not roll after the wheel will continue to move a small amount of distance private float Mousexrecord; Private float mousescrollrecord;//update is called once per framevoid update () {Float MouseX = Input.getaxis ("Mouse X"); float Mousescroll = Input.getaxis ("Mouse scrollwheel"); if (Input.getmousebutton (0)) {if (MouseX! = 0) {transform. Rotatearound (Targetobj.position, Targetobj.up, MouseX * rotatespeed * time.deltatime); Mousexrecord = MouseX; }} if (Mousescroll! = 0) {//print (Vector3.distance (targetobj.position,transform.position )); Vector3 A = transform.position + (targetobj.position-transform.position) * Mousescroll * translatespeed * Time . deltatime; float distance = vector3.distance (Targetobj.position, a); if ((Distance > Mindistance) && (Distance < maxdistance)) transform.position = A; Mousescrollrecord = Mousescroll; }} void Lateupdate () {if (Isinertiarot && input.getmousebuttonup (0)) {in Vokerepeating ("Rotate", 0,time.deltatime); Startcoroutine (Stoprotate (0.5f)); } if (Isinertiatra && (Input.getaxis ("Mouse scrollwheel") = = 0) && (mousescrollrecord! = 0)) {invokerepeating ("Translate", 0, Time.deltatime); Startcoroutine (stoptranslate (2f)); Isinertiatra = false; }} void Rotate () {transform. Rotatearound (Targetobj.position, Targetobj.up, Mousexrecord * rotatespeed * time.deltatime); } void Translate () {Vector3 a = transform.position + (targetobj.position-transform.position) * Mousescroll Record * Translatespeed * time.deltatime; float distance = vector3.distance (Targetobj.position, a); if ((Distance > Mindistance) && (Distance < maxdistance)) transform.position = A; } IEnumerator Stoprotate (float time) {yield return new waitforseconds (time); Cancelinvoke ("Rotate"); Mousexrecord = 0; } IEnumerator Stoptranslate (float time) {yield return new waitforseconds (time); Cancelinvoke ("Translate"); Mousescrollrecord = 0; Isinertiatra = true; }}
[Unity Combat] camera watch objects