|
@@ -3,7 +3,6 @@ |
3 |
3 |
|
|
4 |
4 |
|
public class AllyShip : MonoBehaviour |
5 |
5 |
|
{ |
6 |
|
- |
|
7 |
6 |
|
public SU_Thruster[] thrusters; |
8 |
7 |
|
public float rollRate = 100.0f; |
9 |
8 |
|
public float yawRate = 30.0f; |
|
@@ -13,6 +12,7 @@ |
13 |
12 |
|
public AudioClip[] soundEffectFire; |
14 |
13 |
|
public CameraFollow followCamera; |
15 |
14 |
|
public float life = 100; |
|
15 |
+ |
|
16 |
16 |
|
private bool isAlive = true; |
17 |
17 |
|
|
18 |
18 |
|
private Rigidbody _cacheRigidbody; |
|
@@ -22,7 +22,9 @@ |
22 |
22 |
|
|
23 |
23 |
|
private GameObject currentEnemyTarget; |
24 |
24 |
|
|
25 |
|
- |
public static float ROTATION_SPEED = 0.75f; // degrees |
|
25 |
+ |
private static float ROTATION_SPEED = 0.75f; // degrees |
|
26 |
+ |
private static float SHOOT_RANGE = 2000.0f; |
|
27 |
+ |
private static float MIN_ENGAGE_RANGE = 300.0f; |
26 |
28 |
|
|
27 |
29 |
|
private static float HERO_MIN_RANGE = 1000.0f; |
28 |
30 |
|
private static float HERO_MAX_RANGE = 2000.0f; |
|
@@ -48,6 +50,7 @@ |
48 |
50 |
|
Debug.LogError("Thruster array not properly configured. Attach thrusters to the game object and link them to the Thrusters array."); |
49 |
51 |
|
} |
50 |
52 |
|
} |
|
53 |
+ |
|
51 |
54 |
|
_cacheRigidbody = rigidbody; |
52 |
55 |
|
if (_cacheRigidbody == null) |
53 |
56 |
|
{ |
|
@@ -57,10 +60,10 @@ |
57 |
60 |
|
|
58 |
61 |
|
public void getHitted(float hit) |
59 |
62 |
|
{ |
60 |
|
- |
if(!isAlive) return; |
|
63 |
+ |
if (!isAlive) return; |
61 |
64 |
|
|
62 |
65 |
|
life -= hit; |
63 |
|
- |
if(life<=0) |
|
66 |
+ |
if (life<=0) |
64 |
67 |
|
{ |
65 |
68 |
|
isAlive = false; |
66 |
69 |
|
Instantiate(GameManager.Instance.explosionEffect, this.transform.position, this.transform.rotation); |
|
@@ -68,8 +71,7 @@ |
68 |
71 |
|
Destroy(this.gameObject); |
69 |
72 |
|
} |
70 |
73 |
|
} |
71 |
|
- |
|
72 |
|
- |
|
|
74 |
+ |
|
73 |
75 |
|
void StartThruster() |
74 |
76 |
|
{ |
75 |
77 |
|
foreach (SU_Thruster _thruster in thrusters) |
|
@@ -77,6 +79,7 @@ |
77 |
79 |
|
_thruster.StartThruster(); |
78 |
80 |
|
} |
79 |
81 |
|
} |
|
82 |
+ |
|
80 |
83 |
|
void StopThruster() |
81 |
84 |
|
{ |
82 |
85 |
|
foreach (SU_Thruster _thruster in thrusters) |
|
@@ -84,15 +87,18 @@ |
84 |
87 |
|
_thruster.StopThruster(); |
85 |
88 |
|
} |
86 |
89 |
|
} |
|
90 |
+ |
|
87 |
91 |
|
void Update() |
88 |
92 |
|
{ |
89 |
93 |
|
lastShootTime+=Time.deltaTime; |
90 |
|
- |
if(currentEnemyTarget==null) |
|
94 |
+ |
|
|
95 |
+ |
if (currentEnemyTarget == null) |
91 |
96 |
|
{ |
92 |
97 |
|
//Debug.Log ("Find target"); |
93 |
|
- |
currentEnemyTarget = GameManager.GetClosestEnemy(transform); |
|
98 |
+ |
currentEnemyTarget = GameManager.GetClosestShip(GameManager.ENEMY_TAG, this.gameObject); |
94 |
99 |
|
} |
95 |
|
- |
if(currentEnemyTarget) |
|
100 |
+ |
|
|
101 |
+ |
if (currentEnemyTarget) |
96 |
102 |
|
{ |
97 |
103 |
|
Transform enemyShip = currentEnemyTarget.transform; |
98 |
104 |
|
Debug.DrawLine(transform.position, enemyShip.position, Color.yellow); |
|
@@ -108,8 +114,7 @@ |
108 |
114 |
|
Vector3 newDir = Vector3.RotateTowards (this.transform.forward, relative, step, 0.0f); |
109 |
115 |
|
this.transform.rotation = Quaternion.LookRotation (newDir); |
110 |
116 |
|
|
111 |
|
- |
|
112 |
|
- |
if(distance<300) |
|
117 |
+ |
if (distance<MIN_ENGAGE_RANGE) |
113 |
118 |
|
{ |
114 |
119 |
|
StopThruster(); |
115 |
120 |
|
} |
|
@@ -118,7 +123,7 @@ |
118 |
123 |
|
StartThruster(); |
119 |
124 |
|
} |
120 |
125 |
|
|
121 |
|
- |
if ((distance<2000) && (Vector3.Dot (relative, transform.forward)>0.5) && (lastShootTime>shootFreq)) |
|
126 |
+ |
if ((distance<SHOOT_RANGE) && (Vector3.Dot (relative, transform.forward)>0.5) && (lastShootTime>shootFreq)) |
122 |
127 |
|
{ |
123 |
128 |
|
lastShootTime=0; |
124 |
129 |
|
foreach (Vector3 _wmp in weaponMountPoints) |