public bool InRange(float range, EGameActorType type) { var colliders = Physics.OverlapSphere(this.transform.transform.position, range); for (int i = 0; i < colliders.Length; i++) { var gameActor = colliders[i].GetComponent <GameActor>(); if (gameActor != null && gameActor.actorProps.Type == type) { return(true); } } return(false); }
/// <summary> /// Gets the actors in range. /// </summary> /// <returns>The actors in range.</returns> /// <param name="range">Range.</param> /// <param name="type">Type.</param> public GameActor[] GetActorsInRange(float range, EGameActorType type) { var colliders = Physics.OverlapSphere(this.transform.position, range); List <GameActor> actorList = new List <GameActor>(); for (int i = 0; i < colliders.Length; i++) { var gActor = colliders[i].GetComponent <GameActor>(); if (gActor != null) { actorList.Add(gActor); } } return(actorList.ToArray()); }
/// <summary> /// Gets the less distant actor in range. /// </summary> /// <returns>The actor in range.</returns> /// <param name="range">Range.</param> /// <param name="type">Type.</param> public GameActor GetActorInRange(float range, EGameActorType type) { GameActor gameActor = null; var distance = Mathf.Infinity; var colliders = Physics.OverlapSphere(this.transform.position, range); for (int i = 0; i < colliders.Length; i++) { var mActor = colliders[i].GetComponent <GameActor>(); if (mActor != null && mActor.actorProps.Type == type) { var dist = Vector3.Distance(this.transform.position, mActor.transform.position); if (dist < distance) { distance = dist; gameActor = mActor; } } } return(gameActor); }