-
Notifications
You must be signed in to change notification settings - Fork 0
/
EnemyController.cs
47 lines (37 loc) · 1.02 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
40
41
42
43
44
45
46
47
using UnityEngine;
using System.Collections;
/*
* File Name : EnemyController.cs
* Author : Austin Khamsisavadty 100942529
* Last Modified : 10/30/2016
* Date Last Modified : 10/30/2016
* Description : Controls enemys
* Revision : 1.0
* */
public class EnemyController : MonoBehaviour {
[SerializeField]
private float speed = 0.05f;
private Transform _transform;
private Vector2 _currentPosition;
// Initialization
void Start () {
_transform = gameObject.GetComponent<Transform>();
_currentPosition = _transform.position;
Reset ();
}
// Update is called once per frame
void FixedUpdate () {
_currentPosition = _transform.position;
_currentPosition -= new Vector2 (speed, 0);
_transform.position = _currentPosition;
if (_currentPosition.x <= -5) {
Reset ();
}
}
public void Reset(){//reset enemy
float xpos = Random.Range (6f, 20f);
float ypos = Random.Range (-2.5f, 2.6f);
_currentPosition = new Vector2 (xpos, ypos);
_transform.position = _currentPosition;
}
}