-
Notifications
You must be signed in to change notification settings - Fork 0
/
cam.cs
69 lines (62 loc) · 2.31 KB
/
cam.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
using UnityEngine;
using System.Collections;
public class cam : MonoBehaviour {
public Camera camera;
public Transform player1;
public Transform player2;
public Transform player3;
public Transform player4;
private float mid2x;
private float mid2y;
private float mid3x;
private float mid3y;
private float mid4x;
private float mid4y;
private float scaleX;
private float scaleY;
private int countOfPlayers = 4;
void Start() {
foreach(Transform t in getArr()) {
if(t == null)
countOfPlayers--;
}
scaleX = gameObject.transform.localScale.x;
scaleY = gameObject.transform.localScale.y;
}
void Update() {
switch(countOfPlayers) {
case 1:
gameObject.transform.position = new Vector3(getArr()[0].position.x, getArr()[0].position.y, -10);
break;
case 2:
mid2x = (getArr()[0].position.x + getArr()[1].position.x) / 2;
mid2y = (getArr()[0].position.y + getArr()[1].position.y) / 2;
gameObject.transform.position = new Vector3(mid2x, mid2y, -10);
break;
case 3:
mid3x = (getArr()[0].position.x + getArr()[1].position.x + getArr()[2].position.x) / 3;
mid3y = (getArr()[0].position.y + getArr()[1].position.y + getArr()[2].position.y) / 3;
gameObject.transform.position = new Vector3(mid3x, mid3y, -10);
break;
case 4:
mid4x = (getArr()[0].position.x + getArr()[1].position.x + getArr()[2].position.x + getArr()[3].position.x) / 4;
mid4y = (getArr()[0].position.y + getArr()[1].position.y + getArr()[2].position.y + getArr()[3].position.x) / 4;
gameObject.transform.position = new Vector3(mid3x, mid3y, -10);
break;
}
}
Transform[] getArr() {
Transform[] arr = { player1, player2, player3, player4 };
//ArrayList arr = new ArrayList();
//arr.Add(player1);
//arr.Add(player2);
//arr.Add(player3);
//arr.Add(player4);
return arr;
}
void OnTriggerStay2D(Collider2D c) {
while(c.gameObject.tag != "hero") {
camera.orthographicSize += 0.2f;
}
}
}