Array of gameobjects and finding closest in c++

Hello, im trying to make an array of gameobjects of gameobjects with the tag “Bullet”, and then find the closest gameobject with the tag “bullet”. thanks for any help at all.

my script atm is:

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

public class EnemyScript : MonoBehaviour {

public Vector2 EnemyPos;
public Vector2 PlayerPos;
public float Distance;
public float DistanceToKill;
public float Health;
public GameObject[] Bullets;



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

// Update is called once per frame
void Update () {

    EnemyPos = transform.position;
    PlayerPos = GameObject.FindGameObjectWithTag("Player").transform.position;

    Distance = Vector2.Distance(PlayerPos, EnemyPos);

    if(Distance < DistanceToKill)
    {
        Destroy(GameObject.FindGameObjectWithTag("Player"));
    }

    if(Health <= 0)
    {
        Destroy(gameObject);
    }

    }
}

There’s a lot going wrong here.

  1. Go through all of the scripting tutorials in the Learn section over and over again until you understand them.
  2. Don’t use Find functions in Update, they are slow and should only used in Start (), or once in a while if you have to. Usually you want to save anything new that comes in after Start () so you don’t have to call find later.
  3. There are no bullets anywhere doing anything in this script, you just declared an array. Is this enemy supposed to be shooting bullet? Should there be a script on each bullet checking to see if it collides with the player? and maybe if it’s traveled too far and should destroy itself?
  4. Don’t use public stuff if you don’t have to. Set it in the script.

here’s some quick changes for starters:

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

public class EnemyScript : MonoBehaviour {
	GameObject player;

	float DistanceToKill = 10f;
	float Health = 15f;
	GameObject[] Bullets;

	// Use this for initialization
	void Start () {
		player = GameObject.FindGameObjectWithTag("Player");
	}

	// Update is called once per frame
	void Update () {
		float Distance = Vector2.Distance(player.transform.position, transform.position);
		if(Distance < DistanceToKill)
		{
			Destroy(player);
		}

		if(Health <= 0)
		{
			Destroy(gameObject);
		}
	}
}

i tried making a OnCollisionEnter somthing with Void OnCollosionEnter (collider Col){
something to find the tag of the gameobject (cant remember what the code was)

if(tag == “Bullet”){
Destroy gameobject;
}

but that didnt work at all.

The game is where u fly up, and “enemies” are stationary in the air and u have to shoot them before you fly into them and die, so the bullet is fired from the player, but as he shoots a shit ton of them (20 shots per sec) i needed an array.

i tried to read about arrays and find guides and what not, but i dont understand anything of what they are saying, and usually when i need a command, or a part of a script to work and i cant find a solution, then if i get handed one i get it right away, which is why i asked for it.