Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #region
- using System;
- using UnityEngine;
- #endregion
- [Serializable]
- public class Eyes
- {
- public float fieldOfView = 60.0f;
- public Transform transform;
- public float viewDistance = Mathf.Infinity;
- public bool TargetIsReachable(Vector3 targetPosition)
- {
- var distance = Vector3.Distance(this.transform.position, targetPosition);
- if (this.TargetIsInSight(targetPosition))
- {
- var hits = Physics.RaycastAll(this.transform.position, targetPosition - this.transform.position, distance);
- foreach (var hit in hits)
- if (hit.transform.root.gameObject.isStatic)
- return false;
- return true;
- }
- return false;
- }
- public bool TargetIsInSight(Vector3 targetPosition)
- {
- var distance = Vector3.Distance(this.transform.position, targetPosition);
- if (distance > this.viewDistance)
- return false;
- if (Vector3.Angle(this.transform.position + this.transform.forward, targetPosition) > this.fieldOfView)
- return false;
- return true;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement