public bool Find(GameObject target, bool showLines = false) { if (target == null || owner == null) { return(false); } bool result = false; Vector3 origin = owner.position; float angle = SetAimDirection(-owner.right); for (int i = 0; i <= rayCount; i++) { RaycastHit2D[] hits = Physics2D.RaycastAll(origin, Vector3Ext.GetVectorFromAngle(angle), viewDistance, mask); if (hits.Any()) { foreach (RaycastHit2D hit in hits) { if (hit.collider.gameObject == self) { continue; } Color c = Color.green; if (target != null && hit.collider.gameObject == target) { c = Color.red; result = true; } if (showLines) { Debug.DrawLine(origin, hit.point, c, Time.deltaTime); } break; } } else if (showLines) { Debug.DrawLine(origin, origin + Vector3Ext.GetVectorFromAngle(angle) * viewDistance, Color.green, Time.deltaTime); } angle -= angleIncrease; } return(result); }