I have a list of knights, and some code that checks to see if a knight has lost all his health. If he has, the code should remove him from the list of knights. However, I get this error:
ArgumentOutOfRangeException: Argument is out of range.
Parameter name: index
Any help would be appreciated
Here’s the code:
public void CheckHealth()
{
for(int i = knightsList.Count; i > 0; i-- )
{
if (knightsList*.health <= 0)*
-
{*
_ knightsList.Remove(knightsList*);_
_ }_
_ }_
_ }*_