using System.Collections; using System.Collections.Generic; using UnityEngine; public class PatrolBat : Enemy { public Transform[] path; public int currentPoint; public Transform currentGoal; public float roundingDistance; private Rigidbody2D myRigidbody; //public Transform target; public Animator anim; // Start is called before the first frame update void Start() { myRigidbody = GetComponent(); anim = GetComponent(); } // Update is called once per frame void Update() { if (Vector3.Distance(transform.position, path[currentPoint].position) > roundingDistance) { Vector3 temp = Vector3.MoveTowards(transform.position, path[currentPoint].position, moveSpeed * Time.deltaTime); //changeAnim(temp - transform.position); myRigidbody.MovePosition(temp); } else { changeGoal(); } } private void changeGoal() { if (currentPoint == path.Length - 1) { currentPoint = 0; currentGoal = path[0]; } else { currentPoint++; currentGoal = path[currentPoint]; } } }