CameraCtrl
using UnityEngine;
using System.Collections;
public class CameraCtrl : MonoBehaviour {
public Transform cam; //当前的Cam
public bool isCamRotateAndTranslate = false; //摄像机是否旋转和移动
public bool isRotate = false; //摄像机是否旋转
/// <summary>
/// 摄像机平滑的移动
/// </summary>
/// <param name="camPt"></param>
/// <param name="tm"></param>
public void camSmTo(Transform camPt, float tm)
{
iTween.MoveTo(cam.gameObject,
iTween.Hash("x", camPt.position.x,
"y", camPt.position.y,
"z", camPt.position.z,
"time", tm,
"easetype", iTween.EaseType.linear));
iTween.RotateTo(cam.gameObject, iTween.Hash("x", camPt.eulerAngles.x,
"y", camPt.eulerAngles.y,
"z", camPt.eulerAngles.z,
"time", tm,
"easetype", iTween.EaseType.linear));
}
public void camSmTo(string camPtName, float tm)
{
Transform camPt = transform.Find(camPtName);
camSmTo(camPt, tm);
// Debug.LogWarning(camPtName);
}
/// <summary>
/// 摄像机移动
/// </summary>
/// <param name="camPtName"></param>
public void camTo(string camPtName)
{
Transform camPt = transform.Find(camPtName);
camTo(camPt);
}
public void camTo(Transform camPt)
{
cam.position = camPt.position;
cam.rotation = camPt.rotation;
}
void FixedUpdate()
{
if (isCamRotateAndTranslate)
{
camRotateandTranslate(cam);
}
if (isRotate)
{
camRotate(cam);
}
}
public void camRotateandTranslate(Transform campt)
{
campt.RotateAround(new Vector3(0,30,0),new Vector3(0,1,0),1f );
campt.transform.Translate(Vector3.up * 0.6f);
campt.transform.Translate(Vector3.forward * 0.5f);
}
public void camRotate(Transform campt)
{
campt.RotateAround(new Vector3(0,69f,0),new Vector3(0,1,0),(290/14)*Time.deltaTime);
// campt.Translate(Vector3.up*0.1f);
}
}