42 lines
1.0 KiB
C#
42 lines
1.0 KiB
C#
using System.Collections;
|
|
using System.Collections.Generic;
|
|
using UnityEngine;
|
|
|
|
public class EnemyController_Stupid : MonoBehaviour
|
|
{
|
|
[SerializeField] Rigidbody2D body;
|
|
[SerializeField] float diff = 10.0f;
|
|
[SerializeField] float smoothness = 2f;
|
|
|
|
[SerializeField] int border = 32;
|
|
|
|
int intentX = 0;
|
|
int intentY = 0;
|
|
|
|
// Start is called before the first frame update
|
|
void Start()
|
|
{
|
|
body = GetComponent<Rigidbody2D>();
|
|
StartCoroutine(PickSomewhere());
|
|
}
|
|
|
|
IEnumerator PickSomewhere() {
|
|
while (true) {
|
|
intentX = Random.Range(-480/2 + border, 480/2 - border);
|
|
intentY = Random.Range(-270/2 + border, 270/2 - border);
|
|
yield return new WaitForSeconds(100.0f / diff);
|
|
}
|
|
}
|
|
|
|
// Update is called once per frame
|
|
void FixedUpdate()
|
|
{
|
|
Vector2 vel = body.velocity;
|
|
Vector2.SmoothDamp(transform.position,
|
|
new Vector2(intentX, intentY),
|
|
ref vel,
|
|
smoothness);
|
|
body.velocity = vel;
|
|
}
|
|
}
|