2023-07-24 16:38:13 +03:00
|
|
|
using System.Collections;
|
|
|
|
using System.Collections.Generic;
|
|
|
|
using UnityEngine;
|
|
|
|
|
|
|
|
public class EnemyAI : MonoBehaviour
|
|
|
|
{
|
|
|
|
[SerializeField]
|
2023-08-01 11:28:14 +03:00
|
|
|
private float _sideTimeChangeInterval;
|
|
|
|
[SerializeField]
|
|
|
|
private float _randomOffset = 0.5f;
|
2023-07-24 16:38:13 +03:00
|
|
|
|
|
|
|
private ShipMoveSides moveSides;
|
|
|
|
private float newX = 10;
|
|
|
|
|
|
|
|
private void Awake()
|
|
|
|
{
|
|
|
|
moveSides = GetComponent<ShipMoveSides>();
|
|
|
|
}
|
|
|
|
|
|
|
|
private void Start()
|
|
|
|
{
|
|
|
|
StartCoroutine(ChangeSide());
|
|
|
|
}
|
|
|
|
|
|
|
|
private IEnumerator ChangeSide()
|
|
|
|
{
|
|
|
|
while (true)
|
|
|
|
{
|
|
|
|
newX = Random.Range(-moveSides.Radius, moveSides.Radius);
|
2023-08-01 11:28:14 +03:00
|
|
|
yield return new WaitForSeconds(_sideTimeChangeInterval + Random.Range(-_randomOffset, _randomOffset));
|
2023-07-24 16:38:13 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
private void Update()
|
|
|
|
{
|
|
|
|
moveSides.UpdateInput(Mathf.Clamp(transform.localPosition.x - newX, -1, 1));
|
|
|
|
}
|
|
|
|
}
|