-
Notifications
You must be signed in to change notification settings - Fork 0
/
pvo_launcher.cs
126 lines (115 loc) · 3.38 KB
/
pvo_launcher.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
125
126
using UnityEngine;
using System.Collections;
public class pvo_launcher : MonoBehaviour {
public int range=2200;
public float lift_speed=15;
public float reload_time=25;
public Vector3[] start_points;
GameObject[] rockets;
public float height=5;
bool ready_ru=false;
bool ready_rd=false;
bool ready_lu=false;
bool ready_ld=false;
byte i=0;
Transform tld=null;Transform trd=null;Transform tru=null;Transform tlu=null;
void Awake () {
if (Global.nongamescene) Destroy(this);
rockets=new GameObject[8];
}
// 2 1
// 3 4
// Update is called once per frame
void Update () {
if (Global.pause) return;
for (i=0;i<8;i++) {
if (rockets[i]==null) {
rockets[i]=Instantiate(Global.r_simple_hmissile,transform.TransformPoint(start_points[i/2]+new Vector3(0,i%2,0)),transform.rotation) as GameObject;
rockets[i].transform.parent=transform;
}
else {
if (rockets[i].transform.localPosition.y<start_points[i/2].y+height-i%2) rockets[i].transform.Translate(Vector3.up*lift_speed*Time.deltaTime,Space.Self);
else {
switch (i/2) {
case 1:ready_rd=true;break;
case 2:ready_ld=true;break;
case 3:ready_lu=true;break;
case 4: ready_ru=true;break;
}
}
}
}
if (Input.GetKeyDown("3")) {
if (ready_rd) {trd=Scan(1);if (trd!=null) Fire (1);}
if (ready_ld) {tld=Scan(2);if (tld!=null) Fire(2);}
if (ready_lu) {tlu=Scan(3);if (tlu!=null) Fire(3);}
if (ready_ru) {tru=Scan(4);if (tru!=null) Fire(4);}
}
}
Transform Scan(byte id) {
Collider[] cds=Physics.OverlapSphere(transform.position,range);
if (cds.Length==0) return(null);
Vector3 inpos=Vector3.zero;
float mindist=range;
Transform pt=null;
Transform ctr=null;
foreach (Collider cd in cds) {
ctr=cd.transform.root;
inpos=transform.InverseTransformPoint(ctr.position);
if (ctr.GetComponent<batcopter>()==null&&ctr.GetComponent<plane>()==null||inpos.z<0) continue;
if ((id==1||id==4)&&inpos.x<0||(id==2||id==3)&&inpos.x>0) continue;
if (inpos.magnitude<mindist) {
if (ctr==trd||ctr==tru||ctr==tlu||ctr==tld) continue;
mindist=inpos.magnitude;
pt=ctr;
}
}
return (pt);
}
void Fire(byte id) {
simple_hmissile hmc1=null;
simple_hmissile hmc2=null;
switch (id) {
case 1:
if (trd==null||!ready_rd) return;
hmc1=rockets[0].GetComponent<simple_hmissile>();
hmc2=rockets[1].GetComponent<simple_hmissile>();
hmc1.target=trd;
hmc2.target=trd;
trd=null;
ready_rd=false;
break;
case 2:
if (tld==null||!ready_ld) return;
hmc1=rockets[2].GetComponent<simple_hmissile>();
hmc2=rockets[3].GetComponent<simple_hmissile>();
hmc1.target=tld;
hmc2.target=tld;
tld=null;
ready_ld=false;
break;
case 3:
if (tlu==null||!ready_lu) return;
hmc1=rockets[4].GetComponent<simple_hmissile>();
hmc2=rockets[5].GetComponent<simple_hmissile>();
hmc1.target=tlu;
hmc2.target=tlu;
tlu=null;
ready_lu=false;
break;
case 4:
if (tru==null||!ready_ru) return;
hmc1=rockets[6].GetComponent<simple_hmissile>();
hmc2=rockets[7].GetComponent<simple_hmissile>();
hmc1.target=tru;
hmc2.target=tru;
tru=null;
ready_ru=false;
break;
}
hmc1.enabled=true;
hmc1.gameObject.transform.parent=null;
hmc2.enabled=true;
hmc2.gameObject.transform.parent=null;
}
}