-
Notifications
You must be signed in to change notification settings - Fork 0
/
shoulder_launcher.cs
79 lines (73 loc) · 1.92 KB
/
shoulder_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
using UnityEngine;
using System.Collections;
public class shoulder_launcher : MonoBehaviour {
public ParticleSystem launch_ps;
public Vector3 gun_point=new Vector3(-2,-2,7);
public byte rows=2;
public byte count=4;
Texture icon=null;
bool ready=true;
public float cooldown=30;
float t=0;
byte slot_number=0;
int k=16;
public float duration=0.1f;
byte n=0;
public byte maxpassing=10;
byte passing=0;
// Use this for initialization
void Awake () {
if (Global.nongamescene) Destroy(this);
}
void Start () {
icon=gameObject.GetComponent<moduleInfo>().picture;
k=Screen.height/27;
}
// Update is called once per frame
void Update () {
if (Global.pause||!Global.playable) return;
if (t>0) {
t-=Time.deltaTime;
if (t<=0) {t=0;ready=true;}
}
if (ready&&Input.GetKeyDown("2")) {
ready=false;
launch_ps.Play();
StartCoroutine(Launch());
passing=maxpassing;
n=0;
}
}
IEnumerator Launch() {
GameObject x=null;
byte i=0;
if (n<rows) {
for (i=0;i<count;i++) {
yield return new WaitForSeconds(duration);
x=Instantiate(Global.r_simple_rocket,transform.TransformPoint(gun_point+new Vector3(n,i,0)),transform.rotation) as GameObject;
x.transform.forward=Global.aim-x.transform.position;
}
}
n++;
if (n==rows) {passing--;n=0;}
if (passing==0) {
launch_ps.Stop();
yield return new WaitForSeconds(cooldown);
ready=true;
}
else {StartCoroutine(Launch());}
}
public void SlotNumber (byte x) {
slot_number=x;
}
void OnGUI () {
if (Global.pause||!Global.playable) return;
GUI.DrawTexture(new Rect(slot_number*2*k,0,k,k),icon,ScaleMode.StretchToFill);
if (ready) {
GUI.DrawTexture(new Rect(slot_number*2*k+k,k,k,k),Global.ind_green_tx,ScaleMode.StretchToFill);
}
else {
GUI.DrawTexture(new Rect(slot_number*2*k+k,k,k,k),Global.ind_red_tx,ScaleMode.StretchToFill);
}
}
}