title: How can I create a instantiate my border around a "bronze" when it is the closest and destroy the border when no longer the closest?
body: <p>I've been stuck at this for a while. What I want is for my outline object to be instantiated at the location of my bronze Base game object and for it to destroy when the bronze base is no longer the closest to the player.</p>
  <p>I'm willing to completely restart my bronze script if it means I can make this easier.</p>
  <p>Thanks in advance!</p>
  <p>Find Closest Bronze Script</p>
  <pre><code>using System.Collections;
  using System.Collections.Generic;
  using System.Diagnostics;
  using UnityEngine;
  
  public class FindBronze : MonoBehaviour
  {
      void Update()
      {
          FindClosestBronze();
      }
      void FindClosestBronze()
      {
          float distanceToClosestBronze = Mathf.Infinity;
          Bronze closestBronze = null;
          Bronze[] allBronze = GameObject.FindObjectsOfType&lt;Bronze&gt;();
  
          foreach (Bronze currentBronze in allBronze)
          {
              float distanceToBronze = (currentBronze.transform.position - this.transform.position).sqrMagnitude;
              if (distanceToBronze &lt; distanceToClosestBronze)
              {
                  distanceToClosestBronze = distanceToBronze;
                  closestBronze = currentBronze;
              }
              if (distanceToBronze &gt; distanceToClosestBronze)
              {
                  closestBronze.GetComponent&lt;Bronze&gt;().notSelected();
                  
              }
  
              closestBronze.GetComponent&lt;Bronze&gt;().Selected();
          }
      }
  }
  </code></pre>
  <p>Bronze (includes outline) script</p>
  <pre><code>using System.Collections;
  using System.Collections.Generic;
  using UnityEngine;
  
  public class Bronze : MonoBehaviour
  {
      public bool isSelected = false;
      public Animator anim;
      [SerializeField]
      public GameObject selectedBox;
      public GameObject bronzeBase;
      private GameObject clone;
      // Update is called once per frame
      void Awake()
      {
          clone = (GameObject)Instantiate(selectedBox, bronzeBase.transform);
  
      }
      public void Selected()
      {
          if (!isSelected)
          {
  
             clone = (GameObject)Instantiate(selectedBox, bronzeBase.transform);
              isSelected = true;
  
          }
          
          else
          {
              Destroy(clone);
              isSelected = false;
          }
      }
      public void notSelected()
      {
         
          Destroy(selectedBox);
      }   
  
  }
  </code></pre>