ElectricityBusinessHall_Dig.../Assets/GameAssets/Scripts/CameraCollisionDetection.cs

65 lines
1.3 KiB
C#

using System.Collections;
using System.Collections.Generic;
using UnityEngine;
/// <summary>
/// 检测摄像机是否接触到屋顶
/// </summary>
public class CameraCollisionDetection : MonoBehaviour
{
/// <summary>
/// 是否离开了屋顶
/// </summary>
public bool isLeave = false;
public BoxCollider boxCollider;
public static CameraCollisionDetection inst;
void Awake()
{
inst = this;
}
// Start is called before the first frame update
void Start()
{
boxCollider = GetComponent<BoxCollider>();
}
// Update is called once per frame
void Update()
{
}
/// <summary>
/// 刚进入屋顶
/// </summary>
/// <param name="other"></param>
private void OnTriggerEnter(Collider other)
{
if (other.transform.tag == "MainCamera")
isLeave = false;
}
/// <summary>
/// 在屋顶中
/// </summary>
/// <param name="other"></param>
private void OnTriggerStay(Collider other)
{
if(other.transform.tag=="MainCamera")
isLeave = false;
}
/// <summary>
/// 刚离开入屋顶
/// </summary>
/// <param name="other"></param>
private void OnTriggerExit(Collider other)
{
if (other.transform.tag == "MainCamera")
isLeave = true;
}
}