using System.Collections; using System.Collections.Generic; using UnityEngine; public class EnemyAI : MonoBehaviour { [SerializeField] private float _sideTimeChangeInterval; [SerializeField] private float _randomOffset = 0.5f; private ShipMoveSides moveSides; private ShipPathFollower pathFollower; private float newX = 10; private void Awake() { moveSides = GetComponent(); pathFollower = GetComponent(); } private void Start() { StartCoroutine(ChangeSide()); } private IEnumerator ChangeSide() { while (true) { newX = Random.Range(-moveSides.Radius, moveSides.Radius); yield return new WaitForSeconds(_sideTimeChangeInterval + Random.Range(-_randomOffset, _randomOffset)); } } private void Update() { moveSides.UpdateInput(Mathf.Clamp(transform.localPosition.x - newX, -1, 1)); pathFollower.AddForce(1); } }