M
Mystic
Guest
I already have all of the code inside of the step event. It checks if a player is in range of an enemy, the gun appears in the enemy's hand and aims towards the player. What I have in the step event for this is:
When I run this, I expect obj_shotgunner_gun to spawn on top of the enemy (enemy not shown in code, but enemy has a step event that holds this code) when I am in a certain range (200px). Usually what happens is the gun appears on top of him and dissapears when I leave, which is what I want. But upon killing the enemy (destroying the instance), the enemy is destroyed while obj_shotgunner_gun is still there. Near the beginning of my step event (the segment that checks if the enemy's health is equal to or less than 0 (not d'n'd)), I have this.
Even when the object is destroyed, the instance of the gun remains. How do I fix this?
Hopefully I provided enough code/context for this to be clear.
Code:
if distance_to_object(obj_player_boss) < 200 {
if instance_exists(obj_shotgunner_gun) {
if distance_to_object(obj_shotgunner_gun) > 10 {
if !distance_to_object(obj_shotgunner_gun) < 2 {
instance_create(x,y,obj_shotgunner_gun)
}
}
} else {
instance_create(x,y,obj_shotgunner_gun)
}
Code:
if enemyhp<=0 {
instance_destroy(self)
audio_play_sound(snd_death,1,false)
global.gold+=20
global.kills+=1
instance_destroy(instance_nearest(x,y,obj_shotgunner_gun))
}
Hopefully I provided enough code/context for this to be clear.