using DG.Tweening;
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class CameraResXianZhi : SingletonMono
{
// Start is called before the first frame update
Vector3 pos;
Vector3 v; 物体与摄像机的向量
public bool GenSui;
GameObject Cam;
Tweener tw1;
public GameObject MoveObj;
private void Awake()
{
Cam = Camera.main.gameObject;
}
void Start()
{
}
// Update is called once per frame
void Update()
{
if (GenSui)
{
FloowObj(MoveObj);
}
pos = Camera.main.transform.position;
pos.x = Mathf.Clamp(pos.x, -8f, 8f);
pos.y = Mathf.Clamp(pos.y, 0.5f, 1.5f);
if (Camera.main.transform.position.x <-3.5f)
{
pos.z = Mathf.Clamp(pos.z, -1f, 2.5f);
}
else
{
pos.z = Mathf.Clamp(pos.z, -4f, 2.5f);
}
Camera.main.transform.position = pos;
}
public float ClampAngle(float angle, float min, float max)
{
if (angle < -360)
angle += 360;
if (angle > 360)
angle -= 360;
return Mathf.Clamp(angle, min, max);
}
/// <summary>
/// 相机跟随
/// </summary>
/// <param name="obj"></param>
public void FloowObj(GameObject obj)
{
Cam.transform.LookAt(obj.transform); //摄像机朝向物体
v = (obj.transform.position - Cam.transform.position) ;
//移动动画
tw1 = Cam.transform.DOLocalMove(obj.transform.position - v.normalized * 2.5f, 1);
tw1.SetEase(Ease.Linear);
tw1.Play();
}
}