public IEnumerator InvestigateSound(float lookTime) { //run search animation _moveState = AIState.Search; yield return new WaitForSeconds(lookTime); Path = Pathways[PathwayCount]; AIPath CheckpointScript = Path.GetComponent<AIPath>(); string CheckpointCountString = CheckpointCount.ToString(); ChangeNavPoint(CheckpointCountString, CheckpointScript.getPoints()[CheckpointCount - 1]); }
void Patrol() { /* * enemy.meshRendererFlag.material.color = Color.green; * enemy.navMeshAgent.destination = enemy.wayPoints[nextWayPoint].position; * enemy.navMeshAgent.Resume(); * * if (enemy.navMeshAgent.remainingDistance <= enemy.navMeshAgent.stoppingDistance && !enemy.navMeshAgent.pathPending) * { * nextWayPoint = (nextWayPoint + 1) % enemy.wayPoints.Length; * } */ if (enemy.navMeshAgent.remainingDistance <= enemy.navMeshAgent.stoppingDistance && !enemy.navMeshAgent.pathPending) { enemy.Path = enemy.Pathways[enemy.PathwayCount]; AIPath CheckpointScript = enemy.Path.GetComponent <AIPath>(); if (enemy.PathwayCount <= enemy.Pathways.Count - 1) { if (enemy.Path == null) { Debug.Log("there is no assigned path"); return; } //have the searchcheck here? if the current checkpoint search is true then search switch (enemy.PathType[enemy.PathwayCount]) { case 0: //From A to B to C etc (one way) if (enemy.CheckpointCount < CheckpointScript.getPoints().Count) { Debug.Log(CheckpointScript.getSearch()[enemy.CheckpointCount]); enemy.navPoint = CheckpointScript.getPoints()[enemy.CheckpointCount]; if (enemy.CheckpointCount != CheckpointScript.getPoints().Count) { enemy.CheckpointCount++; } } else { if (enemy.PathwayCount != enemy.Pathways.Count - 1) { enemy.PathwayCount++; enemy.CheckpointCount = 0; } else { return; } } break; case 1: //looping if (enemy.LoopCount <= enemy.nofLoops[enemy.PathwayCount]) { if (enemy.CheckpointCount < CheckpointScript.getPoints().Count) { enemy.navPoint = CheckpointScript.getPoints()[enemy.CheckpointCount]; Debug.Log(enemy.CheckpointCount); if (enemy.CheckpointCount != CheckpointScript.getPoints().Count) { enemy.CheckpointCount++; } } else { enemy.CheckpointCount = 0; if (!enemy.infinite[enemy.PathwayCount]) { enemy.LoopCount++; } } } else { enemy.PathwayCount++; enemy.CheckpointCount = 0; enemy.LoopCount = 1; } break; case 2: //back and forth if (enemy.LoopCount <= enemy.nofLoops[enemy.PathwayCount]) { if ((enemy.CheckpointCount < CheckpointScript.getPoints().Count) && (enemy.back == false)) { Debug.Log(CheckpointScript.getSearch()[enemy.CheckpointCount]); enemy.navPoint = CheckpointScript.getPoints()[enemy.CheckpointCount]; if (enemy.CheckpointCount != CheckpointScript.getPoints().Count) { enemy.CheckpointCount++; } } else { if (enemy.CheckpointCount > 0) { Debug.Log(CheckpointScript.getSearch()[enemy.CheckpointCount]); enemy.back = true; enemy.CheckpointCount--; string CheckpointCountString = enemy.CheckpointCount.ToString(); enemy.navPoint = CheckpointScript.getPoints()[enemy.CheckpointCount]; } else { enemy.back = false; if (!enemy.infinite[enemy.PathwayCount]) { enemy.LoopCount++; } } } } else { enemy.PathwayCount++; enemy.CheckpointCount = 0; enemy.LoopCount = 1; } break; case 3: //guard a single point if (enemy.CheckpointCount < CheckpointScript.getPoints().Count) { Debug.Log(CheckpointScript.getSearch()[enemy.CheckpointCount]); string CheckpointCountString = enemy.CheckpointCount.ToString(); enemy.navPoint = CheckpointScript.getPoints()[enemy.CheckpointCount]; if (enemy.navMeshAgent.remainingDistance <= enemy.navMeshAgent.stoppingDistance && !enemy.navMeshAgent.pathPending) { enemy.transform.rotation = Quaternion.RotateTowards(enemy.transform.rotation, CheckpointScript.getRotations()[enemy.CheckpointCount], enemy.searchingTurnSpeed * 2 * Time.deltaTime); } } break; } } else { } } enemy.meshRendererFlag.material.color = Color.green; enemy.navMeshAgent.destination = enemy.navPoint; enemy.navMeshAgent.Resume(); }
public void nextCheckpoint() { if (_moveState == AIState.Search) { return; } #region LoopPath if (PathwayCount <= Pathways.Count - 1) { Path = Pathways[PathwayCount]; if (Path == null) { return; } AIPath CheckpointScript = Path.GetComponent<AIPath>(); switch (PathType[PathwayCount]) { case 0: if (CheckpointCount < CheckpointScript.getPoints().Count) { string CheckpointCountString = CheckpointCount.ToString(); ChangeNavPoint(CheckpointCountString, CheckpointScript.getPoints()[CheckpointCount]); if (CheckpointCount != CheckpointScript.getPoints().Count) { CheckpointCount++; } } else { if (PathwayCount != Pathways.Count - 1) { PathwayCount++; CheckpointCount = 0; } else { return; } } break; case 1: if (LoopCount <= nofLoops[PathwayCount]) { if (CheckpointCount < CheckpointScript.getPoints().Count) { string CheckpointCountString = CheckpointCount.ToString(); ChangeNavPoint(CheckpointCountString, CheckpointScript.getPoints()[CheckpointCount]); if (CheckpointCount != CheckpointScript.getPoints().Count) { CheckpointCount++; } } else { CheckpointCount = 0; if (!infinite[PathwayCount]) { LoopCount++; } } } else { PathwayCount++; CheckpointCount = 0; LoopCount = 1; } break; case 2: if (LoopCount <= nofLoops[PathwayCount]) { if ((CheckpointCount < CheckpointScript.getPoints().Count) && (back == false)) { string CheckpointCountString = CheckpointCount.ToString(); ChangeNavPoint(CheckpointCountString, CheckpointScript.getPoints()[CheckpointCount]); if (CheckpointCount != CheckpointScript.getPoints().Count) { CheckpointCount++; } } else { if (CheckpointCount > 0) { back = true; CheckpointCount--; string CheckpointCountString = CheckpointCount.ToString(); ChangeNavPoint(CheckpointCountString, CheckpointScript.getPoints()[CheckpointCount]); } else { back = false; if (!infinite[PathwayCount]) { LoopCount++; } } } } else { PathwayCount++; CheckpointCount = 0; LoopCount = 1; } break; case 3: if (CheckpointCount < CheckpointScript.getPoints().Count) { string CheckpointCountString = CheckpointCount.ToString(); ChangeNavPoint(CheckpointCountString, CheckpointScript.getPoints()[CheckpointCount]); } break; } } else { } }
// Update is called once per frame void FixedUpdate() { if (_moveState == AIState.Dazed) { float r = gameObject.GetComponent<Renderer>().material.color.r; float g = gameObject.GetComponent<Renderer>().material.color.g; float b = gameObject.GetComponent<Renderer>().material.color.b; r = Mathf.MoveTowards(r, 0.5f, Time.deltaTime / dazeTimer); g = Mathf.MoveTowards(g, 0.5f, Time.deltaTime / dazeTimer); b = Mathf.MoveTowards(b, 0.5f, Time.deltaTime / dazeTimer); gameObject.GetComponent<Renderer>().material.color = new Color(r, g, b); return; } if (_moveState == AIState.Search) { return; } //sets the destination to mesh.SetDestination(navPoint); if (CheckForTargetsRunning == false) { CheckForTargetsRunning = true; GetTargets(); } if (target != null) { //if the target is in attack distance it will attack the target. If it is the shadow player destroy it. If the target is the player reset the level. if ((attackDistance >= Vector3.Distance(transform.position, target.transform.position) && (chasing == true))) { //Time.timeScale = 0; Application.LoadLevel(Application.loadedLevel); } } if ((Vector3.Distance(transform.position, navPoint) < 3) && (chasing == false)) { nextCheckpoint(); } if (seesTarget == true) { if (suspicionLevel < suspicionLimit) { if (IncrementsuspicionRunning == false) { IncrementsuspicionRunning = true; StartCoroutine("IncrementSuspicion"); } } else //if suspicion is at max { gameObject.GetComponent<Renderer>().material.color = Color.yellow; if (aggressionLevel < aggressionLimit) { if (IncrementaggressionRunning == false) { IncrementaggressionRunning = true; StartCoroutine("Incrementaggression"); } } else //if aggression is at max { chasing = true; sightAngle = chasingSightAngle; ChangeNavPoint(target.name, target.transform.position); SetSpeed(runSpeed); gameObject.GetComponent<Renderer>().material.color = Color.red; _moveState = AIState.Chasing; } } } else //if the target is not seen { //if the AIs aggression level is greater than 0 and it can't find the player decrease aggression if (aggressionLevel > 0) { if (DecrementaggressionRunning == false) { DecrementaggressionRunning = true; StartCoroutine("Decrementaggression"); } } else //if aggression is at 0 { if (suspicionLevel > 0) { if (DecrementsuspicionRunning == false) { DecrementsuspicionRunning = true; StartCoroutine("Decrementsuspicion"); } } else //if suspicion is at 0 { gameObject.GetComponent<Renderer>().material.color = Color.grey; chasing = false; sightAngle = passiveSightAngle; if (PathwayCount < Pathways.Count) { Path = Pathways[PathwayCount]; if (Path == null) { return; } AIPath CheckpointScript = Path.GetComponent<AIPath>(); string CheckpointCountString = CheckpointCount.ToString(); int points = CheckpointScript.getPoints().Count; if (CheckpointCount < points) { ChangeNavPoint(CheckpointCountString, CheckpointScript.getPoints()[CheckpointCount]); } _moveState = AIState.Move; SetSpeed(speed); //return to path } } } } }