public bool DetectNear(out AbstractController controller, AbstractController.Type owner) { AbstractController target; controller = null; bool find = false; foreach (var detect in detects) { bool active = detect.DetectNear(out target, owner); if (active && !find) { controller = target; } else if (active && (target.transform.position - transform.position).magnitude < (controller.transform.position - transform.position).magnitude) { controller = target; } find |= active; } return(find); }
public bool DetectNear(out AbstractController controller, AbstractController.Type owner) { controller = null; bool find = false; detectZone.RemoveAll(ctx => ctx == null); foreach (var detect in detectZone) { if (detect.type != owner && Vector3.Angle(transform.rotation * Vector3.forward, detect.gameObject.transform.position - transform.position) < angle) { if (!find || (controller.transform.position - transform.position).magnitude > (detect.transform.position - transform.position).magnitude) { controller = detect; find = true; } } } return(find); }