unity--Androidはカメラを回転させてオブジェクトを表示し、角度とズーム距離を制限します



Unity Android Rotate Camera View Objects



using System.Collections using System.Collections.Generic using UnityEngine public class ScaleAndRotate : MonoBehaviour { /*app, finger touch (Touc) screen, the script is mounted on the camera, rotate the camera to view the object, and limit the angle and zoom in, the script is mounted on the camera */ Public GameObject target//target moving object Private Touch oldTouch1 // Last touch point 1 (finger 1) Private Touch oldTouch2 // Last touch point 2 (finger 2) private float eulerAngles_x private float eulerAngles_y / / Horizontal scroll related Public float xSpeed ​​= 5.0f / / main camera horizontal rotation speed //Vertical scrolling related Public int yMaxLimit = 90 / / maximum y (unit is the angle) Public int yMinLimit = -90//minimum y (unit is angle) Public float ySpeed ​​= 10.0f / / main camera longitudinal rotation speed void Start() { Vector3 eulerAngles = this.transform.eulerAngles//The Euler angle of the current object this.eulerAngles_x = eulerAngles.y this.eulerAngles_y = eulerAngles.x } void Update() { //No touch if (Input.touchCount 0 && Vector3.Distance(this.transform.position, target.transform.position) > 4) { transform.Translate(Vector3.forward * 0.1f) } if (offset <0 && Vector3.Distance(this.transform.position, target.transform.position) < 10) { transform.Translate(Vector3.forward * -0.1f) } //Remember the latest touch points, next time oldTouch1 = newTouch1 oldTouch2 = newTouch2 } / / Limit the angle to a given range public float ClampAngle(float angle, float min, float max) { while (angle 360) { angle -= 360 } return Mathf.Clamp(angle, min, max) } }

転載:https://www.jianshu.com/p/742d46c49669