Item Drops Only Instantiate On A Single Enemy

I am currently mid-way through developing a 2D Indie game (Using c#). However, I have been stuck on a bug that has stopped me from proceeding with my project. Any help would be greatly appreciated.

What I want to happen: After destroying an enemy, It then drops an item on its location of death.

What is happening: After destroying an enemy out of the 20 or so on the level, the drop from the enemy will only instantiate on a certain enemy, even if it was not the one destroyed, and will keep dropping the item whenever you kill the other enemies. For example, if I destroyed Enemy A, it would drop on Enemy B. On the other hand, if I were to destroy Enemy B, it would drop on Enemy B, and also not drop on Enemy A when that is destroyed.

My code for Enemy Health:

My Code for Dropping the Key: 56882-screenhunter-04.jpg

Any help would be really great :slight_smile:

Thanks in advance


I think the issue is that in your EnemyHealthManager class, you are using GameObject.FindObjectOfType, which is finding one instance of the DropKey component in your scene, then you repeatedly call the DropKeyOnDeath method on that same component. It’s not clear from your description, but it seems like you have a DropKey component on every enemy, in which case you should instead find the DropKey component using GetComponent to find the instance of that component on the enemy.

Where u get the keyvelocity from