rabidus-test/Assets/Scripts/EnemyAI.cs

39 lines
879 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;
[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);
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));
}
}