-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathCameraControl.cs
124 lines (109 loc) · 4.73 KB
/
CameraControl.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
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
using UnityEngine;
using System.Collections;
public class CameraControl : MonoBehaviour {
public Director director;
public int screenHeight;
// Use this for initialization
void Start () {
}
// Update is called nce per frame
void Update () {
screenHeight = Screen.height;
float mousePosX = Input.mousePosition.x;
float mousePosY = Input.mousePosition.y;
int scrollDistance = 1;
float scrollSpeed = 30;
// at the end of player's turn, the camera will snap to the first enemy unit that is alive [1 - 4]
if (Director.cam && !Director.hasMoved)
{
// if enemy unit 1 is alive
if (director.eunit1.transform.gameObject.GetComponent<EnemyUnit>().isAlive == true) {
float x = director.eunit1.transform.position.x - transform.position.x;
float y = director.eunit1.transform.position.y - transform.position.y;
float z = director.eunit1.transform.position.z - transform.position.z;
transform.Translate((x * 2 * Time.deltaTime), 0, ((z - 5) * 2 * Time.deltaTime), Space.World);
}
// if enemy unit 2 is alive
else if (director.eunit2.transform.gameObject.GetComponent<EnemyUnit>().isAlive == true) {
float x = director.eunit2.transform.position.x - transform.position.x;
float y = director.eunit2.transform.position.y - transform.position.y;
float z = director.eunit2.transform.position.z - transform.position.z;
transform.Translate((x * 2 * Time.deltaTime), 0, ((z - 5) * 2 * Time.deltaTime), Space.World);
}
// if enemy unit 3 is alive
else if (director.eunit3.transform.gameObject.GetComponent<EnemyUnit>().isAlive == true) {
float x = director.eunit3.transform.position.x - transform.position.x;
float y = director.eunit3.transform.position.y - transform.position.y;
float z = director.eunit3.transform.position.z - transform.position.z;
transform.Translate((x * 2 * Time.deltaTime), 0, ((z - 5) * 2 * Time.deltaTime), Space.World);
}
// if enemy unit 4 is alive
else if (director.eunit4.transform.gameObject.GetComponent<EnemyUnit>().isAlive == true) {
float x = director.eunit4.transform.position.x - transform.position.x;
float y = director.eunit4.transform.position.y - transform.position.y;
float z = director.eunit4.transform.position.z - transform.position.z;
transform.Translate((x * 2 * Time.deltaTime), 0, ((z - 5) * 2 * Time.deltaTime), Space.World);
}
}
// just after the enemy turn, the camera will snap to the first player unit that is alive [1 - 4]
if (Director.hasMoved) {
// if player unit 1 is alive
if (director.punit1.transform.gameObject.GetComponent<PlayerUnit>().isAlive == true) {
Vector3 newPos = new Vector3(director.punit1.transform.position.x, transform.position.y, director.punit1.transform.position.z);
transform.position = newPos;
Director.hasMoved = false;
}
// if player unit 2 is alive
if (director.punit2.transform.gameObject.GetComponent<PlayerUnit>().isAlive == true) {
Vector3 newPos = new Vector3(director.punit2.transform.position.x, transform.position.y, director.punit2.transform.position.z);
transform.position = newPos;
Director.hasMoved = false;
}
// if player unit 3 is alive
if (director.punit3.transform.gameObject.GetComponent<PlayerUnit>().isAlive == true) {
Vector3 newPos = new Vector3(director.punit3.transform.position.x, transform.position.y, director.punit3.transform.position.z);
transform.position = newPos;
Director.hasMoved = false;
}
// if player unit 4 is alive
if (director.punit4.transform.gameObject.GetComponent<PlayerUnit>().isAlive == true) {
Vector3 newPos = new Vector3(director.punit4.transform.position.x, transform.position.y, director.punit4.transform.position.z);
transform.position = newPos;
Director.hasMoved = false;
}
}
// controls panning the camera
if ((transform.position.x < 10) && (Director.cam == false))
{
//Allows the camera to move right
if (mousePosX >= Screen.width - scrollDistance)
{
transform.Translate(Vector3.right * scrollSpeed * Time.deltaTime);
}
}
if ((transform.position.x > -10) && (Director.cam == false))
{
//Allows the camera to move left
if (mousePosX < scrollDistance)
{
transform.Translate(Vector3.right * -scrollSpeed * Time.deltaTime);
}
}
if ((transform.position.z < -5) && (Director.cam == false))
{
//Allows the camera to move up
if (mousePosY >= Screen.height - scrollDistance)
{
transform.Translate((new Vector3(0,0,1) * scrollSpeed * Time.deltaTime), Space.World);
}
}
if ((transform.position.z > -27) && (Director.cam == false))
{
//Allows the camera to move down
if (mousePosY < scrollDistance)
{
transform.Translate((new Vector3(0,0,-1) * scrollSpeed * Time.deltaTime), Space.World);
}
}
}
}