Help Me!! I don't recognize you at all!

I’m making a side-scrolling shoot em’up game in Unity. I put the following code on an enemy character to put a special move gauge in the game, but it turns out to be null and doesn’t respond at all. Please tell me what to do.

using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class EnemyCore : MonoBehaviour {
public float HP = 1;
public int GetScore = 400;
public float GetPower = 10;
public GameObject Explotion;

void Awake(){
	
}

// Use this for initialization
void Start () {
}

// Update is called once per frame
void Update () {
	if(HP <= 0){
		Destroy(gameObject);
		Instantiate(Explotion,transform.position,transform.rotation);
		ScoreScript.ScoreValue += GetScore;
		Ship Ship = GetComponent<Ship>();
		Ship.Hyper.CurrentVal += 10;
	}
}

void OnTriggerEnter2D(Collider2D other){
	if(other.gameObject.tag == "Player Bullet"){
		HP -= 1;
	}

	if(other.gameObject.tag == "Player Mega Bullet"){
		HP -= 3;
	}

	if(other.gameObject.tag == "Player Giga Bullet"){
		HP -= 5;
	}
}

}

Hi,

You cannot call Destroy(gameObject);and add instruction after, your gameobject containing the script will be destroyed and therefore your script.

You have to destroy it after the script is complete.

First Solution :

     if(HP <= 0){
         Instantiate(Explotion,transform.position,transform.rotation);
         ScoreScript.ScoreValue += GetScore;
         Ship Ship = GetComponent<Ship>();
         Ship.Hyper.CurrentVal += 10;
         Destroy(gameObject);
     }

Second Solution (more elegante) :

private void Update () {
    // Your stuff
    if(HP <= 0){
        Destroy(gameObject);
    }
   // Your stuff
}

private void OnDestroy() {
    Instantiate(Explotion,transform.position,transform.rotation);
    ScoreScript.ScoreValue += GetScore;
    Ship Ship = GetComponent<Ship>();
    Ship.Hyper.CurrentVal += 10;
}

Thanks !!