Instantiate problem [When Player Dies]

Hello,
I have a problem because when the player die [ has health <= 0 ] does this

	currentGun.GetComponent(GunScript).beingHeld = false;
	currentGun.rigidbody.AddRelativeForce(Vector3(0, throwGunUpForce, throwGunForwardForce));
	Instantiate(deadbodyPrefab, transform.position, transform.rotation);
	collider.enabled = false;
	cameraObject.GetComponent(AudioListener).enabled = false;
	enabled = false;
	Debug.Log("Player Died");

But the enemy is attacking him even when player is dead and it spawns a lot of ‘deadbodyprefab’.
How to make it so if player has less then 0 health it does this but only once, so it will spawn just one deadbodyprefab.

Thanks for helping!

Do u ever disable the player??? i know u create a player prefab but do u disable the player completely so this script cant keep activating because the player health would keep being less then 0??

I dont know i think no
How to do this

OO i just did it :smile: i added the code
Destroy(this.gameObject);
but when the players dies im getting error
MissingReferenceException: The object of type ‘Transform’ has been destroyed but you are still trying to access it.
Your script should either check if it is null or you should not destroy the object.
UnityEngine.Transform.get_position () (at C:/BuildAgent/work/d3d49558e4d408f4/artifacts/EditorGenerated/UnityEngineTransform.cs:27)
Enemy.Update () (at Assets/Scripts/Enemy.js:53)

but i think its ok because after when player dies i will make some gui menu that you can restart level or something so i think this error doesnt matter :smile: