Advertisement
Guest User

Untitled

a guest
Oct 18th, 2018
76
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.47 KB | None | 0 0
  1. void Update () {
  2. foreach (Transform agentPosition in agentsTransform) {
  3. if (CanSeeAgent (agentPosition) && state != State.Arresting && !agentPosition.GetComponent<Agent> ().agentIsDown && !enemyDown) {
  4. agentVisibleTimer += Time.deltaTime;
  5. StopAllCoroutines ();
  6. state = State.Arresting;
  7. aiCharacterControl.SetTarget (agentPosition);
  8. StartCoroutine (AttackAgent (agentPosition));
  9. // StartCoroutine (SpawnProjectile (agentPosition)); // TODO switch to Coroutines
  10. } else if (state == State.Arresting && !enemyDown) {
  11. float distanceToAgent = Vector3.Distance (agentPosition.position, transform.position);
  12. if (distanceToAgent >= chaseRadius && state != State.Searching) {
  13. agentVisibleTimer -= Time.deltaTime;
  14. StopAllCoroutines ();
  15. // StopCoroutine (SpawnProjectile (agentPosition));
  16. // aiCharacterControl.SetTarget (transform);
  17. StartCoroutine (SearchForAgent ());
  18. }
  19. }
  20. agentVisibleTimer = Mathf.Clamp (agentVisibleTimer, 0, timeToSpotAgent);
  21. spotLight.color = Color.Lerp (originalSpotLightColour, Color.red, agentVisibleTimer / timeToSpotAgent);
  22.  
  23. if (agentVisibleTimer >= timeToSpotAgent) {
  24. if (OnEnemyHasSpottedAgent != null) {
  25. OnEnemyHasSpottedAgent ();
  26. }
  27. }
  28. }
  29. }
  30.  
  31. IEnumerator AttackAgent (Transform agentPoint) {
  32. animator.SetTrigger ("Shooting");
  33. yield return new WaitForSeconds (0.3f);
  34. agentPoint.GetComponent<Agent> ().TakeDamage ();
  35. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement