public void Approach(INPCTarget target) { if (isApproaching) { return; } // var patroler = GetComponent<IPatroling>(); // if (patroler != null && patroler.IsPatroling) // return; isApproaching = true; StartCoroutine(approach = StartApproach(target)); }
override public void Run(StateController controller, GameManager game) { var approacher = controller.GetComponent <IApproacher>(); if (approacher == null) { return; } INPCTarget target = approacher.FindTargetInSight(); if (target == null) { return; } approacher.Approach(target); }
IEnumerator StartApproach(INPCTarget target) { while (true) { if (!transform || target == null) { yield break; } if (Vector3.Distance(transform.position, target.Position) < 0.5f) { yield break; } transform.LookAt(target.Position); transform.position += transform.forward * character.MoveSpeed * Time.fixedDeltaTime; yield return(new WaitForFixedUpdate()); } }