44 lines
1015 B
C#
44 lines
1015 B
C#
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<ShipMoveSides>();
|
|
pathFollower = GetComponent<ShipPathFollower>();
|
|
}
|
|
|
|
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(3);
|
|
}
|
|
}
|