CameraRestraint.cs 757 B

123456789101112131415161718192021222324252627
  1. using System.Collections;
  2. using System.Collections.Generic;
  3. using UnityEngine;
  4. /// <summary>
  5. /// 相机漫游是否穿碰撞器判断
  6. /// </summary>
  7. public class CameraRestraint : MonoBehaviour
  8. {
  9. private static RaycastHit _hit;
  10. /// <summary>
  11. /// 球形射线检测相机是否即将穿过碰撞器
  12. /// </summary>
  13. /// <param name="camera"></param>
  14. /// <param name="pos"></param>
  15. /// <returns></returns>
  16. public static bool CheckThePos(Transform camera,Vector3 pos)
  17. {
  18. if (Physics.SphereCast(camera.position,0.5f,(pos-camera.position).normalized,out _hit ,0.3f))
  19. {
  20. if (_hit.transform.CompareTag("DontCross")) return true;
  21. else return false;
  22. }
  23. return true;
  24. }
  25. }