rabidus-test/Assets/Scripts/EnemyAI.cs

37 lines
773 B
C#
Raw Normal View History

2023-07-24 16:38:13 +03:00
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class EnemyAI : MonoBehaviour
{
[SerializeField]
private float _sideTimeChangeInterval;
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);
yield return new WaitForSeconds(_sideTimeChangeInterval);
}
}
private void Update()
{
moveSides.UpdateInput(Mathf.Clamp(transform.localPosition.x - newX, -1, 1));
}
}