@@ -27,6 +27,9 @@ public class Unit : HealthEntity
2727
2828 public List < Unit > enemiesInSight = new List < Unit > ( ) ;
2929
30+ /// <summary>
31+ /// Adds this unit to some lists of the player and AI controller, depending on which side it is.
32+ /// </summary>
3033 private new void Start ( )
3134 {
3235 base . Start ( ) ;
@@ -48,6 +51,9 @@ public class Unit : HealthEntity
4851 }
4952 }
5053
54+ /// <summary>
55+ /// Calls the Combat and Movement methods depending on if the unit is in combat or not.
56+ /// </summary>
5157 private void FixedUpdate ( )
5258 {
5359 if ( isInCombat )
@@ -61,6 +67,10 @@ private void FixedUpdate()
6167
6268 }
6369
70+ /// <summary>
71+ /// If another unit enters the range of this unit it will be checks and added to a list of enemies in the perimeter.
72+ /// </summary>
73+ /// <param name="other">The collider of the entering unit</param>
6474 private void OnTriggerEnter ( Collider other )
6575 {
6676 if ( other . isTrigger ) return ;
@@ -73,13 +83,23 @@ private void OnTriggerEnter(Collider other)
7383
7484 CheckForEnemiesNearYou ( ) ;
7585 }
76-
86+
87+ /// <summary>
88+ /// If another unit exits the range of this unit it will be removed from the list of enemies in the perimeter.
89+ /// </summary>
90+ /// <param name="other">The collider of the exiting unit.</param>
7791 private void OnTriggerExit ( Collider other )
7892 {
7993 Unit exit = other . transform . GetComponent < Unit > ( ) ;
8094 enemiesInSight . Remove ( exit ) ;
8195 }
8296
97+ /// <summary>
98+ /// This method handles movement. Also its responsible for a functionality of the AI (remarks).
99+ /// </summary>
100+ /// <remarks>The AI has the functionality to first check for units on a point before capturing it and attack them first.
101+ /// This is something the player does naturally and an AI without it is pretty useless.</remarks>
102+ /// Only the first line of this method is the one that manages movement. All other lines are for this functionality.
83103 private void Movement ( )
84104 {
85105 nav . destination = destPoint ;
@@ -116,6 +136,9 @@ private void Movement()
116136
117137 }
118138
139+ /// <summary>
140+ /// If the unit has a set enemy it will walk towards it. If the enemy is already in range it will stop walking and attack the enemy instead.
141+ /// </summary>
119142 private void Combat ( )
120143 {
121144 if ( enemy )
@@ -139,6 +162,9 @@ private void Combat()
139162 }
140163 }
141164
165+ /// <summary>
166+ /// The unit attacks its enemy with the given attack speed. This varies if the enemy is a unit or a base.
167+ /// </summary>
142168 private void Attack ( )
143169 {
144170 if ( _lastAttackTime + attackSpeed <= DateTimeOffset . Now . ToUnixTimeSeconds ( ) )
@@ -163,29 +189,42 @@ private void Attack()
163189 }
164190 }
165191
192+ /// <summary>
193+ /// This method is called if the unit receives damage from another unit.
194+ /// </summary>
195+ /// <remarks>The damage is dealt by calling HealthEntity.TakeDamage(), more there.
196+ /// Also if the unit is not in combat and not moving it is set into combat mode against its attacker.</remarks>
197+ /// <param name="attacker"></param>
198+ /// <param name="damage"></param>
166199 public void TakeDamage ( Unit attacker , float damage )
167200 {
168- // TODO: include proper damage calculation
169201 base . TakeDamage ( damage ) ;
170202
171- if ( ! isInCombat )
203+ // before the unit is set into combat mode it is checked if the unit has a pending movement command
204+ // if so, its not set into combat mode until this path is complete
205+ if ( ! isInCombat && ! IsMoving ( ) )
172206 {
173- // before the unit is set into combat mode it is checked if the unit has a pending movement command
174- // if so, its not set into combat mode until this path is complete
175- if ( ! IsMoving ( ) )
176- {
177- StartCoroutine ( SetIntoCombat ( attacker ) ) ;
178- }
207+ StartCoroutine ( SetIntoCombat ( attacker ) ) ;
179208 }
180209 }
181210
211+ /// <summary>
212+ /// Sets the unit into combat against its attacker after a half second delay.
213+ /// </summary>
214+ /// <remarks>The only cause for the half second delay is so that it wont strike back immediately. So that the
215+ /// attacker always wins a fight.</remarks>
216+ /// <param name="attacker">Reference to the attacking unit.</param>
217+ /// <returns>IEnumerator</returns>
182218 private IEnumerator SetIntoCombat ( Unit attacker )
183219 {
184220 yield return new WaitForSeconds ( 0.5f ) ;
185221 isInCombat = true ;
186222 enemy = attacker ;
187223 }
188224
225+ /// <summary>
226+ /// If this unit is destroyed it should be removed from the list of the player and AI controller that is was placed in during Start().
227+ /// </summary>
189228 private void OnDestroy ( )
190229 {
191230 // if this is a player unit, remove it from the list of active units
@@ -200,11 +239,18 @@ private void OnDestroy()
200239 }
201240 }
202241
242+ /// <summary>
243+ /// Determines if this unit is moving or not.
244+ /// </summary>
245+ /// <returns>Is the unit moving (true) or not (false).</returns>
203246 private bool IsMoving ( )
204247 {
205248 return ! ( nav . remainingDistance <= nav . stoppingDistance + 1 ) ;
206249 }
207250
251+ /// <summary>
252+ /// Checks if there are enemies inside the units range and attacks them if so.
253+ /// </summary>
208254 private void CheckForEnemiesNearYou ( )
209255 {
210256 if ( IsMoving ( ) ) return ;
0 commit comments