public bool CanSee(GameActor actor) { Ray ray = new Ray(this.transform.position, actor.transform.position); RaycastHit hit; if (Physics.Linecast(this.transform.position, actor.transform.position, out hit)) { if (hit.transform.tag == "Obstacle") { return(false); } } return(true); }
/// <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); }
public bool InRange(GameActor actor, float range) { return(Vector3.Distance(this.transform.position, actor.transform.position) > range ? false : true); }