|
@@ -25,56 +25,26 @@ |
25 |
25 |
|
|
26 |
26 |
|
public static float EVADE_DISTANCE = 300.0f; |
27 |
27 |
|
|
28 |
|
- |
public static float WEAPON_AIM = 2.0f; // degrees |
29 |
|
- |
|
30 |
|
- |
private Transform spaceShip; |
31 |
|
- |
private Vector3 _pos; |
32 |
|
- |
private Transform _transform; |
33 |
|
- |
private Vector3 _prePos; |
|
28 |
+ |
public static float WEAPON_AIM = 2.5f; // degrees |
34 |
29 |
|
|
35 |
30 |
|
private float timeToShot = RELOAD_TIME; |
36 |
31 |
|
private int availableShoots = MAX_SHOOTS; |
37 |
32 |
|
|
38 |
33 |
|
private Material mat; |
39 |
|
- |
private WillRender willRender; |
40 |
34 |
|
private bool isAlive = true; |
41 |
35 |
|
|
42 |
36 |
|
void Start() |
43 |
37 |
|
{ |
44 |
|
- |
_transform = transform; |
45 |
|
- |
spaceShip = GameManager.Instance.spaceShip; |
46 |
|
- |
willRender = GetComponentInChildren<WillRender>(); |
47 |
|
- |
SetPath(); |
48 |
|
- |
} |
49 |
38 |
|
|
50 |
|
- |
void SetPath() |
51 |
|
- |
{ |
52 |
39 |
|
if(shipType==ShipType.SMALL_SHIP) |
53 |
40 |
|
{ |
54 |
|
- |
if(spaceShip==null)return; |
55 |
|
- |
|
56 |
|
- |
//_ransform.position = spaceShip.position+new Vector3(Random.value,Random.value,Random.value)*PLAYER_RANGE; |
57 |
|
- |
//_transform.rotation = Random.rotation; |
58 |
|
- |
|
59 |
|
- |
//_transform.localPosition = Vector3.zero; |
60 |
|
- |
//_transform.parent.position = spaceShip.right*Random.Range(-100,100)+spaceShip.up*Random.Range(-100,100)+spaceShip.forward*Random.Range(200,800); |
61 |
|
- |
_transform.position = spaceShip.position+new Vector3(Random.value-Random.value,Random.value-Random.value,Random.value-Random.value)*SMALL_ENEMY_RANGE; |
62 |
|
- |
//spaceShip.right*Random.Range(-100,100)+spaceShip.up*Random.Range(-100,100)+spaceShip.forward*Random.Range(200,800); |
63 |
|
- |
_transform.rotation = Random.rotation; |
64 |
|
- |
|
65 |
|
- |
/* |
66 |
|
- |
iTween.MoveTo(gameObject, iTween.Hash("path", iTweenPath.GetPath("path"+Random.Range(0,5)), |
67 |
|
- |
"speed", Random.Range(40,60), |
68 |
|
- |
"looptype","pingpong", |
69 |
|
- |
"looktarget",spaceShip, |
70 |
|
- |
"islocal",true, |
71 |
|
- |
"oncomplete","OnComplete")); |
72 |
|
- |
*/ |
|
41 |
+ |
this.transform.position = new Vector3(Random.value-Random.value,Random.value-Random.value,Random.value-Random.value)*SMALL_ENEMY_RANGE; |
|
42 |
+ |
this.transform.rotation = Random.rotation; |
73 |
43 |
|
} |
74 |
44 |
|
else |
75 |
45 |
|
{ |
76 |
|
- |
_transform.position = spaceShip.position+new Vector3(Random.value-Random.value,Random.value-Random.value,Random.value-Random.value)*BIG_ENEMY_RANGE; |
77 |
|
- |
_transform.rotation = Random.rotation; |
|
46 |
+ |
this.transform.position = new Vector3(Random.value-Random.value,Random.value-Random.value,Random.value-Random.value)*BIG_ENEMY_RANGE; |
|
47 |
+ |
this.transform.rotation = Random.rotation; |
78 |
48 |
|
} |
79 |
49 |
|
} |
80 |
50 |
|
|
|
@@ -86,14 +56,14 @@ |
86 |
56 |
|
if(life<=0) |
87 |
57 |
|
{ |
88 |
58 |
|
isAlive = false; |
89 |
|
- |
Instantiate(GameManager.Instance.explosionEffect, _transform.position, _transform.rotation); |
|
59 |
+ |
Instantiate(GameManager.Instance.explosionEffect, this.transform.position, this.transform.rotation); |
90 |
60 |
|
if(shipType==ShipType.SMALL_SHIP) |
91 |
61 |
|
{ |
92 |
|
- |
Destroy(_transform.parent.gameObject); |
|
62 |
+ |
Destroy(this.transform.parent.gameObject); |
93 |
63 |
|
} |
94 |
64 |
|
else |
95 |
65 |
|
{ |
96 |
|
- |
Destroy(_transform.gameObject); |
|
66 |
+ |
Destroy(this.transform.gameObject); |
97 |
67 |
|
} |
98 |
68 |
|
CommunicationCenter.Instance.DestroyOneEnemy(ID); |
99 |
69 |
|
} |
|
@@ -106,9 +76,9 @@ |
106 |
76 |
|
DoSmallShip(); |
107 |
77 |
|
} |
108 |
78 |
|
} |
|
79 |
+ |
|
109 |
80 |
|
void OnComplete() |
110 |
81 |
|
{ |
111 |
|
- |
SetPath(); |
112 |
82 |
|
} |
113 |
83 |
|
|
114 |
84 |
|
void Fire() |
|
@@ -119,7 +89,7 @@ |
119 |
89 |
|
Random.Range(-WEAPON_AIM,WEAPON_AIM), |
120 |
90 |
|
Random.Range(-WEAPON_AIM,WEAPON_AIM) |
121 |
91 |
|
); |
122 |
|
- |
small = small*_transform.rotation; |
|
92 |
+ |
small = small*this.transform.rotation; |
123 |
93 |
|
|
124 |
94 |
|
Vector3 _pos = transform.position + transform.right * _wmp.x + transform.up * _wmp.y + transform.forward * _wmp.z; |
125 |
95 |
|
Transform _laserShot = (Transform) Instantiate(laserShotPrefab, _pos, small); |
|
@@ -134,12 +104,14 @@ |
134 |
104 |
|
|
135 |
105 |
|
void DoSmallShip() |
136 |
106 |
|
{ |
|
107 |
+ |
Transform spaceShip = GameManager.Instance.spaceShip; |
|
108 |
+ |
|
137 |
109 |
|
if (spaceShip==null) return; |
138 |
110 |
|
|
139 |
111 |
|
/*** |
140 |
112 |
|
* Navigation routine |
141 |
113 |
|
*/ |
142 |
|
- |
float distance = Vector3.Distance(_transform.position,spaceShip.position); |
|
114 |
+ |
float distance = Vector3.Distance(this.transform.position,spaceShip.position); |
143 |
115 |
|
|
144 |
116 |
|
// The step size is equal to speed times frame time. |
145 |
117 |
|
float step = ROTATION_SPEED * Time.deltaTime; |
|
@@ -150,19 +122,19 @@ |
150 |
122 |
|
|
151 |
123 |
|
if (distance < EVADE_DISTANCE) { |
152 |
124 |
|
// evade!! |
153 |
|
- |
targetDir = Vector3.Cross (_transform.forward, spaceShip.right); |
|
125 |
+ |
targetDir = Vector3.Cross (this.transform.forward, spaceShip.right); |
154 |
126 |
|
|
155 |
127 |
|
|
156 |
128 |
|
} else { |
157 |
|
- |
targetDir = spaceShip.position - _transform.position; |
|
129 |
+ |
targetDir = spaceShip.position - this.transform.position; |
158 |
130 |
|
} |
159 |
131 |
|
|
160 |
|
- |
Debug.DrawLine (_transform.position, _transform.position + targetDir*100.0f, Color.green); |
|
132 |
+ |
Debug.DrawLine (this.transform.position, this.transform.position + targetDir*100.0f, Color.green); |
161 |
133 |
|
|
162 |
|
- |
Vector3 newDir = Vector3.RotateTowards (_transform.forward, targetDir, step, 0.0f); |
163 |
|
- |
_transform.rotation = Quaternion.LookRotation (newDir); |
|
134 |
+ |
Vector3 newDir = Vector3.RotateTowards (this.transform.forward, targetDir, step, 0.0f); |
|
135 |
+ |
this.transform.rotation = Quaternion.LookRotation (newDir); |
164 |
136 |
|
if (distance > MIN_DISTANCE) { |
165 |
|
- |
_transform.Translate( Vector3.forward * speed ); |
|
137 |
+ |
this.transform.Translate( Vector3.forward * speed ); |
166 |
138 |
|
} |
167 |
139 |
|
/*** |
168 |
140 |
|
* Fire routine |
|
@@ -173,8 +145,8 @@ |
173 |
145 |
|
return; |
174 |
146 |
|
} |
175 |
147 |
|
|
176 |
|
- |
targetDir = spaceShip.position - _transform.position; |
177 |
|
- |
float cosAlpha = Vector3.Dot (_transform.forward, targetDir); |
|
148 |
+ |
targetDir = spaceShip.position - this.transform.position; |
|
149 |
+ |
float cosAlpha = Vector3.Dot (this.transform.forward, targetDir); |
178 |
150 |
|
if (cosAlpha < 0.0f) return; |
179 |
151 |
|
|
180 |
152 |
|
if (availableShoots > 0) { |