private void OnTriggerEnter2D(Collider2D collision) { PathFollower pathFollower = collision.GetComponent <PathFollower>(); if (pathFollower != null && index != -1 && index == pathFollower.CurrentFollowedNode) { OnPointReached?.Invoke(index, pathFollower); } }
}//findNodesFromTransform /// <summary> /// /// </summary> /// <param name="whoIsMoving"></param> /// <returns></returns> public GridNode GetNext(Transform targetPoint=null) { GridNode targetNode = null; if(targetPoint == null && this.activePoint == null) targetNode = PatrolPath[0]; if(targetPoint == null && this.activePoint != null) targetNode = this.activePoint; if (targetNode == null) { #if UNITY_EDITOR Debug.LogError("MoveTo targetPoint is null for " + this.name); #endif return null; } int index = PatrolPath.IndexOf(targetNode); if (index < 0) { #if UNITY_EDITOR Debug.Log("GetNext: No targetPoint in the list for " + this.name); #endif return null; } if (index >= PatrolPath.Count - 1) { if(this.waitAtPointRoutine != null) this.waitAtPointRoutine = StartCoroutine(WaitAtWaypoint()); EOnLastPointReached?.Invoke(this); } else if (index <= 0) { if(this.waitAtPointRoutine != null) this.waitAtPointRoutine = StartCoroutine(WaitAtWaypoint()); EOnFirstPointReached?.Invoke(this); } else { EOnPointReached?.Invoke(this); } index += nextNodeIncreaseIndex; if (index >= PatrolPath.Count) index = PatrolPath.Count - 1; else if (index < 0) index = 0; this.activePoint = PatrolPath[index]; return PatrolPath[index]; }//MoveTo