How to destroy an instantiated object

I’m trying to make the asteroid destroy itself after the player gets too far


public Transform transform;
public Rigidbody2D rb;
public Vector2 randomVector;
float rotationForce;
GameObject Player;
private Transform playerTransform;
GameObject Asteroid_PreFab;
GameObject LogicMaster;
private logic_Master logicMaster;

void Awake()
    Player = GameObject.Find("Player");
    Asteroid_PreFab = GameObject.Find("Asteroid_PreFab");
    LogicMaster = GameObject.Find("LogicMaster");

    playerTransform = Player.GetComponent<Transform>();
    logicMaster = LogicMaster.GetComponent <logic_Master> ();


// Use this for initialization
void Start () {

    Vector2 randomVector = new Vector2(Random.Range(-3,3), Random.Range(-3,3));

    Debug.Log(randomVector + "" + randomVector.magnitude);

    rotationForce = Random.Range(-1, 1);

    float scaleFactor = Random.Range(0.5f, 2f);
    Vector2 scaleVector = new Vector2(scaleFactor, scaleFactor);
    transform.localScale = scaleVector;

    rb.velocity = rb.velocity + randomVector;

    rb.AddTorque(rotationForce, ForceMode2D.Impulse);

// Update is called once per frame
void Update()
    Vector2 playerDistance = new Vector2(transform.position.x - playerTransform.position.x, transform.position.y - playerTransform.position.y);

    if (playerDistance.magnitude > 30 )

At the very end when the magnitude exceeds 30, its outputting true as per debug.log, but is not destroying the asteroid.

Asteroid_PreFab = GameObject.Find(“Asteroid_PreFab”);

This will be null if at that time no game objects by that name are found.

Where are you instantiating the prefab by the way? and after you have instantiated it, are you renaming the instantiated object? because otherwise it will be named with a “(Clone)” suffix by default and GameObject.Find(“Asteroid_PreFab”) will fail

it is instantiate that prefab, or it is in the scene from beginning ?
Try this: Destroy(GameObject.Find(“Asteroid_PreFab(Clone)”)); And check the name in Hierachy when the app is running