I recently ran into some problems just passing links to objects / enemies in the game I am making, and I am wondering if I am using the wrong approach.
The main problem I encounter is to destroy enemies and objects when other enemies or players still have references to them.
For example, if you have a Rabbit and a Wolf, the Wolf may have chosen the Rabbit for its purpose. What I do is the wolf has GameObject Target = null; , and when he decides that he is hungry, the target becomes Rabbit. If Rabbit then dies, for example, another wolf killing him, he cannot be removed from the game, because this wolf still has a link to him.
In addition, if you use the untied approach, the rabbit can strike with lightning, reducing its health to zero. When he updates, he realizes that he is dead, and he is removed from the game ... but there is no way to update everything that interests him.
If you provided each enemy with a unique identifier, you could simply use the links to it instead, and also use the central search class that handled it. If the monster is dead, the search class can remove it from its own index, and subsequently everything that tries to access it will be informed that it is dead, and then they can act accordingly.
Any thoughts on this?
oop
Nibblypig
source share