public static IEnumerator followUnit(GameObject subject, GameObject target,float distance=0) { MotionAgent motionAgent = new MotionAgent(subject, target, distance); Instance.agentList.Add(motionAgent); motionAgent.navMeshObstacle.enabled = false; yield return null; motionAgent.navMeshAgent.enabled = true; motionAgent.navMeshAgent.SetDestination(target.transform.position); yield return motionAgent; }
public static IEnumerator moveToPoint(GameObject subject, Vector3 targetPoint) { MotionAgent motionAgent; if (Instance.map.ContainsKey(subject.GetHashCode())) { motionAgent = Instance.map[subject.GetHashCode()]; if (motionAgent.navMeshObstacle.enabled) { motionAgent.navMeshObstacle.enabled = false; yield return null; yield return null; } if (!motionAgent.navMeshAgent.enabled) { motionAgent.navMeshAgent.enabled = true; } } else { motionAgent = new MotionAgent(subject, targetPoint); motionAgent.navMeshObstacle.enabled = false; yield return null; yield return null; motionAgent.navMeshAgent.enabled = true; Instance.map.Add(subject.GetHashCode(), motionAgent); } //Instance.agentList.Add(motionAgent); motionAgent.isStop = false; motionAgent.navMeshAgent.SetDestination(targetPoint); yield return null; Debug.Log(motionAgent.navMeshAgent.remainingDistance); yield return motionAgent; }