rabidus-test/Assets/Scripts/EnemyAI.cs

44 lines
1015 B
C#
Raw Permalink 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;
2023-10-02 19:12:35 +03:00
private ShipPathFollower pathFollower;
2023-07-24 16:38:13 +03:00
private float newX = 10;
private void Awake()
{
moveSides = GetComponent<ShipMoveSides>();
2023-10-02 19:12:35 +03:00
pathFollower = GetComponent<ShipPathFollower>();
2023-07-24 16:38:13 +03:00
}
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));
2023-10-02 19:12:35 +03:00
pathFollower.AddForce(1);
2023-07-24 16:38:13 +03:00
}
}