在做项目的时候,有用到相机绕着某个物体旋转和近距离查看的功能。所以过来贴贴代码。
/// <summary>
/// Mouse orbit.
/// This script use to control a main camera
/// </summary>
using UnityEngine;
using System.Collections;
public class MouseOrbit : MonoBehaviour
{
public GameObject target; //a target look at
public float xSpeed; //speed pan x
public float ySpeed; //speed pan y
public float yMinLimit; //y min limit
public float yMaxLimit; //y max limit
public float scrollSpeed; //scroll speed
public float zoomMin; //zoom min
public float zoomMax; //zoom max
private float distance;
private float distanceLerp;
private Vector3 position;
private bool isActivated;
private float x;
private float y;
// Use this for initialization
void Start()
{
//Warning when not found target
if (target