PappaP

Untitled

May 7th, 2020
690
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 2.86 KB | None | 0 0
  1. using System.Collections;
  2. using System.Collections.Generic;
  3. using UnityEngine;
  4.  
  5. public class PatrolLog : Log
  6. {
  7.  
  8.     public Transform[] path;
  9.     public int currentPoint;
  10.     public Transform currentGoal;
  11.  
  12.     public float roundingDistance = 0.2f;
  13.  
  14.     public int waitSeconds = 2;
  15.     private bool waiting;
  16.  
  17.     // Update is called once per frame
  18.     void Update()
  19.     {
  20.        
  21.     }
  22.  
  23.  
  24.     private void ChangeGoal()
  25.     {
  26.         if (currentPoint == path.Length - 1)
  27.         {
  28.             currentPoint = 0;
  29.             currentGoal = path[0];
  30.         }
  31.         else
  32.         {
  33.             currentPoint++;
  34.             currentGoal = path[currentPoint];
  35.         }
  36.     }
  37.  
  38.     public override void CheckDistance()
  39.     {
  40.         if (!waiting)
  41.         {
  42.             if (player.activeSelf == true)
  43.             {
  44.  
  45.                 if (Vector3.Distance(target.position, transform.position) <= chaseRadius
  46.                     && Vector3.Distance(target.position, transform.position) > attackRadius)
  47.                 {
  48.  
  49.                     if (currentState == enemyState.idle || currentState == enemyState.walk
  50.                         && currentState != enemyState.stagger)
  51.                     {
  52.                         Vector3 temp = Vector3.MoveTowards(transform.position, target.position, moveSpeed * Time.deltaTime);
  53.  
  54.                         ChangeAnim(temp - transform.position);
  55.                         myRigidbody.MovePosition(temp);
  56.  
  57.  
  58.                         ChangeState(enemyState.walk);
  59.                         anim.SetBool("wakeUp", true);
  60.  
  61.                     }
  62.                 }
  63.                 else if (Vector3.Distance(target.position, transform.position) > chaseRadius)
  64.                 {
  65.                     if (Vector3.Distance(transform.position, path[currentPoint].position) > roundingDistance)
  66.                     {
  67.  
  68.  
  69.  
  70.                         //ChangeState(enemyState.idle);
  71.                         //anim.SetBool("wakeUp", false);
  72.                         Vector3 temp = Vector3.MoveTowards(transform.position, path[currentPoint].position, moveSpeed * Time.deltaTime);
  73.  
  74.                         ChangeAnim(temp - transform.position);
  75.                         myRigidbody.MovePosition(temp);
  76.                     }
  77.                     else
  78.                     {
  79.                         //ChangeGoal();
  80.                         StartCoroutine(ChangeGoalWait(waitSeconds));
  81.                     }
  82.                 }
  83.             }
  84.             else
  85.             {
  86.                 ChangeState(enemyState.idle);
  87.                 anim.SetBool("wakeUp", false);
  88.                 myRigidbody.velocity = Vector2.zero;
  89.             }
  90.         }
  91.     }
  92.  
  93.     private IEnumerator ChangeGoalWait(int seconds)
  94.     {
  95.         waiting = true;
  96.         yield return new WaitForSeconds(seconds);
  97.         waiting = false;
  98.         ChangeGoal();
  99.  
  100.     }
  101.  
  102. }
Advertisement
Add Comment
Please, Sign In to add comment