title: Not able to destroy the prefeb object in unity
body: <pre><code>using UnityEngine;
   
   public class Gun : MonoBehaviour
   {
       public GameObject enemy; // Not necessary, only if you need a reference to the enemy for future actions
   
       public float damage = 100f;
   
       void Update()
       {
           if (Input.GetButtonDown(&quot;Fire1&quot;))
           {
               Shoot();
           }
       }
   
   
       void Shoot()  // The are a general routine to program on all laguajes, you should name all functions with Uppercase start letter 
       {
           RaycastHit hit;
   
           if (Physics.Raycast(transform.position, transform.forward, out hit))
           {
               // Target targ = GetComponent&lt;Target&gt;(); // 
   
               Target targ = hit.collider.GetComponent&lt;Target&gt;();
   
               // Now, you have the enemy script values referenced and you can make your actions.
   
               // I dont understand next code, your are not referenig enemy never,  I mean, enemy ever is null
               if (enemy != null)
               {
                   Destroy(enemy);
               }
           }
  </code></pre>
  <p><strong>target.cs:</strong></p>
  <pre><code>using UnityEngine;
  
  public class Target : MonoBehaviour
  {
      // Start is called before the first frame update
  
      public float health = 50f;
  
  
      public void TakeDamage (float amount)
      {
          health -= amount;
          if (health &lt;= 0f)
          {
              Die();
          }
      }
  
      void Die()
      {
          Destroy(gameObject);
      }
  
  }
  </code></pre>