-
Notifications
You must be signed in to change notification settings - Fork 3
/
EnemyController.cs
39 lines (31 loc) · 1.14 KB
/
EnemyController.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
// Enemy Controller File
// Author(s): Spencer DeMera
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class EnemyController : MonoBehaviour {
public float speed;
private float waitTime;
public float startWaitTime;
public Transform moveSpot;
public float minX;
public float maxX;
public float minY;
public float maxY;
void Start () {
waitTime = startWaitTime;
moveSpot.position = new Vector2(Random.Range(minX, maxX), Random.Range(minY, maxY));
} // Start function
void Update () {
transform.position = Vector2.MoveTowards(transform.position, moveSpot.position, speed * Time.deltaTime);
if (Vector2.Distance(transform.position, moveSpot.position) < 0.2f) {
if (waitTime <= 0) {
moveSpot.position = new Vector2(Random.Range(minX, maxX), Random.Range(minY, maxY));
waitTime = startWaitTime;
} // if
else {
waitTime -= Time.deltaTime;
} // else
} // if
} // Update function
} // EnemyController class