The script does only zoom in and out, the angle moves, not the player Moves. The script needs to be mounted on the maincamera, and the protagonist needs to be set to the Player's Tag.
Using unityengine;using system.collections;public class follow : monobehaviour { private transform player;//lead location private Vector3 offsetposition;//offset private bool isrotating = false;/ /toggle direction of rotation public float distance = 0;//distance Public float scrollspeed = 10;//middle button, character Zoom speed public float Rotatespeed = 2;//angle change Speed void start () { player = gameobject.findgameobjectwithtag ("player"). transform;//assigning A value to the player transform. LookAt (player.position);//camera facing role offsetPosition = Transform.position - player.position;//camera position-role position = OFFSET}//&NBSP;UPDATE&NBSP;IS&NBSP;CALLED&Nbsp;once per framevoid update () { Transform.position = offsetposition + player.position;//itself position = offset + role position (follow when character moves) scrollview (); Rotateview (); } void scrollview () { distance = offsetposition.magnitude;// Offset length (distance to Player) distance += -input.getaxis ("Mouse scrollwheel ") * scrollspeed; distance = mathf.clamp (distance, 2, 18);//limit the nearest distance offsetposition = offsetposition.normalized * distance;// print (input.getaxis ("mouse scrolLwheel ")); } void rotateview () { //right mouse button Press if (input.getmousebuttondown (1)) { isRotating = true; } //right mouse button pop up if (input.getmousebuttonup (1)) { isRotating = false; } if (isrotating) { vector3 originalpos&nbsP;= transform.position;//get Maincamera Current coordinates quaternion originalrotation = transform.rotation;//get Maincamera The current rotation situation transform. Rotatearound (player.position, vector3.up, rotatespeed * input.getaxis ("Mouse X"));// X-axis Rotation transform. Rotatearound (player.position, transform.right, -rotatespeed * input.getaxis ("Mouse Y" ));//y Shaft Rotation float x = Transform.eulerangles.x;//get the X-euler angle of the camera // To limit the angle if (x < 10 | | x&nBsp;> 80)//camera height cannot reach angle less than 10 and greater than 80 position { transform.position = originalpos; transform.rotation = originalRotation; } offsetposition = transform.position - player.position;//update offset when rotation is complete (for follow player and zoom In) transform.position } }}
Knowledge Points:
1. Finding objects by Findgameobjectwithtag
Gameobject.findgameobjectwithtag ("Player")
2. Understanding of the use of vectors
3. Limit the range of values for a variable
Mathf.clamp (distance, 2, 18)
4.
Input.getmousebuttondown (0/1/2) left/right/middle Key respectively
Input.getaxis ("Mouse Y")//mouse Swipe
Input.getaxis ("Mouse Scrollwheel")//roller Slide
6.RotateAround () function
7.transform.eulerangles.x//euler Angle
Problem: If you use vector.right, a z-axis rotation occurs.
Unity3d in the View of Warcraft lens