I was implementing a targeting system in my game, but I've got stuck when finding the next target.
About my code:
Local static number "targetMode" is the type of targeting the player is using as it follows:
[1] When activated, targets the closest enemy at that moment. When that enemy is destroyed or offscreen, the targeting mode is disabled.
[2] When activated, targets the closest enemy at that moment. When that enemy is destroyed or offscreen, targets the next closest enemy.
[3] When activated, continuously targets only the closest enemy.
Function "toggleLockOn" activates and stops the targeting system.
Function "setTarget" should target the closest enemy at that moment.
Function "releaseTarget" stops the targeting system.
Function "targetIntro" is the nice effect when the target appears onscreen.
The issue is that after I destroy an enemy that is targeted, the target remains in the same place, so I think the problem is in the function "setTarget" witch picks the same object even if the object should be destroyed.