usingUnityengine;usingSystem.Collections; Public classCameracontroller:monobehaviour { Public floatDistance_v; Public floatDistance_h; Public floatRotation_h_speed=1; Public floatRotation_v_speed=1; Public floatMax_up_angle = the;//the bigger the head, the higher it gets. Public floatMax_down_angle =- -;//the smaller the head, the lower it gets. PublicTransform Follow_obj;//player Private floatCurrent_rotation_h;//Horizontal Rotation result Private floatCurrent_rotation_v;//Vertical Rotation Result voidlateupdate () {//Control Rotationcurrent_rotation_h+= Input.getaxis ("Mouse X")*Rotation_h_speed; Current_rotation_v+ = Input.getaxis ("Mouse Y")*Rotation_v_speed; Current_rotation_v=mathf.clamp (Current_rotation_v, Max_down_angle, Max_up_angle);//Limit Vertical Rotation angleTransform.localeulerangles =NewVector3 (-current_rotation_v,current_rotation_h,0f); //change position to track the target as the center of Vision, and the center of vision is always oriented to Follow_objTransform.position =follow_obj.position; Transform. Translate (Vector3.back*Distance_h, space.self); Transform. Translate (Vector3.up* Distance_v, Space.world);//y-axis upward relative to world coordinates }}
Mouse movement on the screen to control the camera level, vertical rotation