- using System.Collections;
- using System.Collections.Generic;
- using UnityEngine;
- public class QuestNPCMovement : MonoBehaviour
- {
- private Rigidbody2D rb;
- private RangedArea rangedArea;
- [SerializeField] private float moveForce = 1f;
- private Vector3[] positionArray;
- private int pointsIndex;
-
- void Start()
- {
- rangedArea = FindObjectOfType<RangedArea>();
- rb = GetComponent<Rigidbody2D>();
- positionArray = new[] {new Vector3(6f, -10.5f), new Vector3(18.5f, -10.5f),
- new Vector3(18.5f, 8.5f)};
- pointsIndex = 0;
- }
-
- void FixedUpdate()
- {
- if (rangedArea.playerInRange == false)
- {
- transform.position = Vector3.MoveTowards(transform.position, positionArray[pointsIndex], moveForce * Time.deltaTime);
- if (transform.position == (positionArray[pointsIndex]))
- {
-
- pointsIndex++;
- }
- if (pointsIndex == (positionArray.Length))
- {
-
- pointsIndex = 0;
- }
- }
- }
- }