37 lines
773 B
C#
37 lines
773 B
C#
|
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));
|
||
|
}
|
||
|
}
|