/// <summary> /// Set to next Target /// </summary> public virtual void SetTarget(Transform target) { if (!Agent.isOnNavMesh) { return; //No nothing if we are not on a Nav mesh or the Agent is disabled } if (target == null) { return; //If there's no target Skip the code } this.target = target; targetPosition = target.position; //Update the Target Position isActionZone = target.GetComponent <ActionZone>(); isWayPoint = target.GetComponent <MWayPoint>(); NextWayPoint = target.GetComponent <IWayPoint>(); //Check if the Next Target has Next Waypoints StoppingDistance = NextWayPoint != null ? NextWayPoint.StoppingDistance : DefaultStopDistance; if (debug) { Debug.Log("Target Updated: " + target.name); } Agent.SetDestination(targetPosition); //If there's a position to go to set it as destination Agent.isStopped = false; }
/// <summary> /// Set the next Target /// </summary> public virtual void SetTarget(Transform target) { if (target == null) { return; //If there's no target Skip the code } this.target = target; targetPosition = target.position; //Update the Target Position isActionZone = target.GetComponent <ActionZone>(); //TisAnimal = target.GetComponent<Animal>(); (WHAT HAPPENS IF THE TARGET IS AN ANIMAL ???? )) isWayPoint = target.GetComponent <MWayPoint>(); NextWayPoint = target.GetComponent <IWayPoint>(); //Check if the Next Target has Next Waypoints StoppingDistance = NextWayPoint != null ? NextWayPoint.StoppingDistance : DefaultStopDistance; //Set the Next Stopping Distance CheckAirTarget(); Debuging(name + " is travelling to : " + target.name); if (!Agent.isOnNavMesh) { return; //No nothing if we are not on a Nav mesh or the Agent is disabled } Agent.enabled = true; Agent.SetDestination(targetPosition); //If there's a position to go to set it as destination Agent.isStopped = false; //Start the Agent again }
//If the target changes do something void UpdateTarget() { if (deltaTarget != target) { deltaTarget = target; if (debug) { Debug.Log("Target Updated: " + target.name); } Target_is_Animal = deltaTarget ? deltaTarget.GetComponent <Animal>() : null; Target_is_ActionZone = deltaTarget ? deltaTarget.GetComponent <ActionZone>() : null; Target_is_Waypoint = deltaTarget ? deltaTarget.GetComponent <MWayPoint>() : null; Agent.stoppingDistance = DefaultStoppingDistance; if (Target_is_ActionZone) { Agent.stoppingDistance = Target_is_ActionZone.stoppingDistance; } else if (Target_is_Waypoint) { Agent.stoppingDistance = Target_is_Waypoint.StoppingDistance; } } }
/// <summary> /// Manage all Off Mesh Links /// </summary> protected virtual void CheckOffMeshLinks() { if (isFlying) { return; } if (Agent.isOnOffMeshLink && !EnterOFFMESH) //Check if the Agent is on a OFF MESH LINK { EnterOFFMESH = true; //Just to avoid entering here again while we are on a OFF MESH LINK OffMeshLinkData OMLData = Agent.currentOffMeshLinkData; if (OMLData.linkType == OffMeshLinkType.LinkTypeManual) //Means that it has a OffMesh Link component { OffMeshLink CurrentOML = OMLData.offMeshLink; //Check if the OffMeshLink is a Custom Off Mesh Link ActionZone OffMeshZone = CurrentOML.GetComponentInParent <ActionZone>(); if (OffMeshZone && !OnAction) //if the OffmeshLink is a zone and is not making an action { animal.Action = OnAction = true; //Activate the Action on the Animal return; } var DistanceEnd = (transform.position - CurrentOML.endTransform.position).sqrMagnitude; var DistanceStart = (transform.position - CurrentOML.startTransform.position).sqrMagnitude; var NearTransform = DistanceEnd < DistanceStart ? CurrentOML.endTransform : CurrentOML.startTransform; StartCoroutine(MalbersTools.AlignTransformsC(transform, NearTransform, 0.15f, false, true)); //Aling the Animal to the Link Position if (CurrentOML.area == 2) { animal.SetJump(); //if the OffMesh Link is a Jump type } try { if (CurrentOML.CompareTag("Fly")) { animal.SetFly(true); isFlying = true; StartCoroutine(FlyTowardsTarget(CurrentOML.endTransform)); return; } } catch {} } else if (OMLData.linkType == OffMeshLinkType.LinkTypeJumpAcross) //Means that it has a OffMesh Link component { animal.SetJump(); } } }
/// <summary> /// Manage all Off Mesh Links /// </summary> protected virtual void CheckOffMeshLinks() { if (Agent.isOnOffMeshLink) { OffMeshLinkData CurrentOffmeshLink_Data = Agent.currentOffMeshLinkData; OffMeshLink CurrentOffMeshLink = CurrentOffmeshLink_Data.offMeshLink; //Check if the OffMeshLink is a Custom Off Mesh Link ActionZone OffMeshZone = null; if (CurrentOffMeshLink) //Checking if the OffMeshLink is an Action Zone { OffMeshZone = CurrentOffMeshLink.GetComponentInChildren <ActionZone>(); if (!OffMeshZone) { OffMeshZone = CurrentOffMeshLink.GetComponentInParent <ActionZone>(); } } if (OffMeshZone) { if (!StartingAction) //If the Target is an Action Zone Start the Action { StartingAction = true; animal.Action = true; //Activate the Action on the Animal return; } } if (CurrentOffmeshLink_Data.linkType == OffMeshLinkType.LinkTypeManual) { Transform NearTransform = CurrentOffMeshLink.startTransform; if (CurrentOffMeshLink.endTransform.position == CurrentOffmeshLink_Data.startPos) //Verify the start point of the OffMeshLink { NearTransform = CurrentOffMeshLink.endTransform; } StartCoroutine(MalbersTools.AlignTransformsC(transform, NearTransform, 0.5f, false, true)); //Aling the Animal to the Link if (CurrentOffMeshLink.area == 2) //if the OffMesh Link is a Jump type { animal.SetJump(); } } } }
/// <summary> /// Manage all Off Mesh Links /// </summary> protected virtual void CheckOffMeshLinks() { if (Agent.isOnOffMeshLink && !EnterOFFMESH) //Check if the Agent is on a OFF MESH LINK { EnterOFFMESH = true; //Just to avoid entering here again while we are on a OFF MESH LINK OffMeshLinkData OMLData = Agent.currentOffMeshLinkData; if (OMLData.linkType == OffMeshLinkType.LinkTypeManual) //Means that it has a OffMesh Link component { OffMeshLink CurrentOML = OMLData.offMeshLink; //Check if the OffMeshLink is a Manually placed Link ActionZone Is_a_OffMeshZone = CurrentOML.GetComponentInParent <ActionZone>(); //Search if the OFFMESH IS An ACTION ZONE (EXAMPLE CRAWL) if (Is_a_OffMeshZone && !DoingAnAction) //if the OffmeshLink is a zone and is not making an action { animal.Action = DoingAnAction = true; //Activate the Action on the Animal return; } var DistanceEnd = (transform.position - CurrentOML.endTransform.position).sqrMagnitude; var DistanceStart = (transform.position - CurrentOML.startTransform.position).sqrMagnitude; var NearTransform = DistanceEnd < DistanceStart ? CurrentOML.endTransform : CurrentOML.startTransform; var FarTransform = DistanceEnd > DistanceStart ? CurrentOML.endTransform : CurrentOML.startTransform; StartCoroutine(MalbersTools.AlignTransform_Rotation(transform, NearTransform.rotation, 0.15f)); //Aling the Animal to the Link Position if (animal.canFly && CurrentOML.CompareTag("Fly")) { Debuging(name + ": Fly OffMesh"); StartCoroutine(CFlyOffMesh(FarTransform)); } else if (CurrentOML.area == 2) { animal.SetJump(); //if the OffMesh Link is a Jump type } } else if (OMLData.linkType == OffMeshLinkType.LinkTypeJumpAcross) //Means that it has a OffMesh Link component { animal.SetJump(); } } }
private void OnEnable() { mActionZone = ((ActionZone)target); }
private void OnEnable() { M = ((ActionZone)target); script = MonoScript.FromMonoBehaviour((ActionZone)target); }
/// <summary> /// Manage all Off Mesh Links /// </summary> protected virtual void CheckOffMeshLinks() { if (isFlying) { return; } if (Agent.isOnOffMeshLink) { OffMeshLinkData CurrentOffmeshLink_Data = Agent.currentOffMeshLinkData; OffMeshLink CurrentOffMeshLink = CurrentOffmeshLink_Data.offMeshLink; //Check if the OffMeshLink is a Custom Off Mesh Link ActionZone OffMeshZone = null; if (CurrentOffMeshLink) //Checking if the OffMeshLink is an Action Zone { OffMeshZone = CurrentOffMeshLink.GetComponentInChildren <ActionZone>(); if (!OffMeshZone) { OffMeshZone = CurrentOffMeshLink.GetComponentInParent <ActionZone>(); } } if (OffMeshZone) { if (!StartingAction) //If the Target is an Action Zone Start the Action { StartingAction = true; animal.Action = true; //Activate the Action on the Animal return; } } if (CurrentOffmeshLink_Data.linkType == OffMeshLinkType.LinkTypeManual) //Means that it has a OffMesh Link component { Transform NearTransform = CurrentOffMeshLink.startTransform; if (CurrentOffMeshLink.endTransform.position == CurrentOffmeshLink_Data.startPos) //Verify the start point of the OffMeshLink { NearTransform = CurrentOffMeshLink.endTransform; } StartCoroutine(MalbersTools.AlignTransformsC(transform, NearTransform, 0.5f, false, true)); //Aling the Animal to the Link try { if (CurrentOffMeshLink.CompareTag("Fly")) { animal.SetFly(true); isFlying = true; StartCoroutine(FlyTowardsTarget(CurrentOffMeshLink.endTransform)); return; } } catch { /*Debug.LogWarning("There's no Fly Tag");*/ } if (CurrentOffMeshLink.area == 2) //if the OffMesh Link is a Jump type { animal.SetJump(); } } } }