Mathf.Infinity in Unity

you may ask why Mathf.Infinity why not normal value?.

The enemy appears in the order in the hierarchy.
for each only for C# forks
Infinity value in positive infinity value the value I put is just to show you it doesn't end. This is to make beginners understand the logic behind the hood.
Actual code
_closestEnemyDistance default value when script Enabled
this is the actual value that is compared since the first enemy distance is set as the closest Enemy Distance.
The condition will be true since the first enemy is 50000 away from the player so, for now, the closest is this so we set the Closest Enemy Distance to 7000 and set this enemy as ClosestEnemy.
actual value.
actual code.

--

--

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store