using System.Collections;
using System.Collections.Generic;
using UnityEngine;
///
/// 看向摄像机
///
public class LookTrans : MonoBehaviour
{
public static LookTrans Instance;
///
/// 主视角
///
public Transform AimTrans;
///
/// 需要看向摄像机的物体
///
public Transform[] Trans;
///
///
///
Quaternion Qua;
///
/// 旋转角度
///
Vector3 RotV3 = Vector3.zero;
void Awake()
{
Instance = this;
}
void Update()
{
for (int i = 0; i < Trans.Length; i++)
{
if (Trans[i] && Trans[i].gameObject)
{
if (Trans[i].gameObject.activeSelf)
{
Trans[i].LookAt(AimTrans);
RotV3.y = Trans[i].rotation.eulerAngles.y;
Qua.eulerAngles = RotV3;
Trans[i].rotation = Qua;
}
}
}
}
///
/// 添加需要看向摄像机的物体
///
///
public void TransAddTransform(Transform tran)
{
Transform[] _Trans=new Transform[Trans.Length+1];
for (int i = 0; i < Trans.Length; i++)
{
_Trans[i] = Trans[i];
}
_Trans[Trans.Length] = tran;
Trans = _Trans;
}
}