The player attacks first the 2nd enemie behind the first one

I made the changes from “Ignore Dead Enemies” and to test, I set two enemies in a row. But if I click on the first enemie in the row, the player starts to attack the 2nd enemie in this row:

After the 2nd enemie is dead, then I can attack the first one:

So, why (and how can I change this)?

My actually solution is, to start in the foreach at the end:

foreach(RaycastHit hit in hits.Reverse())

But why has the RaycastHit-Array in default the last objects first and the first at last?

Actually, there is generally no guarantee in which order the hits will appear.

Later in the course, Sam will introduce a sorting method to the Raycasts which will ensure that they are all handled in order.

1 Like

This topic was automatically closed 24 hours after the last reply. New replies are no longer allowed.

Privacy & Terms