-
Notifications
You must be signed in to change notification settings - Fork 0
/
building.cs
79 lines (69 loc) · 1.78 KB
/
building.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 building : MonoBehaviour {
public float maxhp=100;
public float hp;
public bool use_dust=false;
public int points=100;
public int fires=0;
float fd=0;
float cd=0;
public int tall=10;
Vector3 null_point=Vector3.zero;
void Start() {
hp=maxhp;
if (fires>0) {
fd=maxhp/fires;
cd=maxhp;
}
RaycastHit rh;
var layerMask=1<<8;
if (Physics.Raycast(transform.position+Vector3.up*100,Vector3.down,out rh,1000,layerMask)) null_point=rh.point;
else {null_point=transform.position-Vector3.down*tall/2;}
}
public void ApplyDamage(Vector4 mg) {
if (mg.w>maxhp) {
Global.menu_script.AddFireplace(transform.position);
Global.score+=points;
Destroy(gameObject);
}
else {
hp-=mg.w;
if (hp<=0) {
if (use_dust) {
Vector3 p=null_point;
while (tall>0) {
p+=transform.TransformDirection(Vector3.up*10);
Global.BigDustRequest(p);
tall-=10;
}
}
Destroy(gameObject);
}
}
if (hp<cd) {
GameObject x=Instantiate(Global.r_fire,new Vector3(mg.x,mg.y,mg.z),Quaternion.LookRotation(new Vector3(mg.x,mg.y,mg.z)-transform.position)) as GameObject;
x.transform.parent=transform;
if (cd>0) cd-=fd;
}
}
void OnCollisionStay (Collision c) {
if (c.collider.transform.root.GetComponent<catmech_physics>()) {
print ("contact");
hp-=10000*Time.deltaTime;
if (Global.sound&&!Global.sm.outside_off)Global.sm.TankCrunch();
if (hp<=0) {
Global.score+=points;
if (use_dust) {
Vector3 p=null_point;
while (tall>0) {
p+=transform.TransformDirection(Vector3.up*10);
Global.BigDustRequest(p);
tall-=10;
}
}
Destroy(gameObject);
}
}
}
}