摄像机安全检测
安全监测的方式有很多种
2.当摄像机发射线可以碰到玩家时,且摄像机当前不在初始位置
如果上一个位置能看到家,则后退一步
如果看不到玩家,不动
public class cameraSafe : MonoBehaviour
{
//在相机下定义一个空节点作为初始位置
public Transform StartPos;
//在相机下定义一个空节点作为结束位置
public Transform EndPos;
//插值的第三个参数
public float t;
// Start is called before the first frame update
void Start()
{
t = 0;
transform.LookAt(transform.parent);
}
// Update is called once per frame
void Update()
{
Ray ray = new Ray(transform.position, (transform.parent.position - transform.position).normalized);
RaycastHit hit;
if (Physics.Raycast(ray, out hit))
{
if (hit.collider.gameObject.tag != "Player")
{
t +&#