using UnityEngine; using System.Collections; public class FollowCamera : MonoBehaviour { public GameObject target; public float minOffset = 0.5f; public float maxOffset = 2.5f; public float zenith; public float azimuth; public float mouseSpeed = 0.1f; private float offset; [Range (-(Mathf.PI * 0.5f), Mathf.PI * 0.5f)] public float minZenith = -(Mathf.PI * 0.5f); [Range (-(Mathf.PI * 0.5f), Mathf.PI * 0.5f)] public float maxZenith = Mathf.PI * 0.5f; /*[Range (-(Mathf.PI * 0.5f), Mathf.PI * 0.5f)] public float minAzimuth = -(Mathf.PI * 0.5f); [Range (-(Mathf.PI * 0.5f), Mathf.PI * 0.5f)] public float maxAzimuth = Mathf.PI * 0.5f;*/ public bool mouseInput = true; private SphericalCoordinate direction = new SphericalCoordinate(); void Start () { offset = minOffset; } void Update () { if (target != null && camera != null) { offset = Mathf.Clamp(offset, minOffset, maxOffset); if(mouseInput){ zenith += Input.GetAxis ("Mouse Y") * mouseSpeed; azimuth -= Input.GetAxis ("Mouse X") * mouseSpeed; } zenith = Mathf.Clamp(zenith, minZenith, maxZenith); direction.ElevationAngle = zenith; direction.PolarAngle = azimuth; camera.transform.position = target.transform.position + direction.Cartesian * offset; camera.transform.LookAt (target.transform); } } }