Why destroy and destroy.Immediate don't work?

I started using unity a week ago, and I’m not very good. I’am trying to reply flappy bird and I need to destroy the pipes when them go outside the screen, I tried with destroy.Immediate(pipe, false) but it does nothing, Destroy(pipe) is the same

this is the script that manages the instantiation and destruction of the pipes.
I hope you can help me, I don’t think I can program a game without destroying objects

Your public GameObject Pipe isn’t actually set to anything. You somehow need to be able to keep track of actual pipe objects so that you can destroy them later. For example, in your PipeIst() method, you grab a reference to “Pipe2” as you create it… but then you don’t do anything with it. As soon as the code exits that method then you lose your reference to that object. It exists in the scene but you don’t have any variables pointing at it, and therefore can’t destroy it in this script because you have lost track of it.
**
So how do you fix this? 2 Options…

  1. You could destroy the pipes in this script, like you are trying to do. You will need to add them to a list (or a queue or a set) so you can keep track of them.

    private List pipeList = new List();

    PipeIst(){
    GameObject newPipe = Instantiate(blah blah blah);
    pipeList.Add(newPipe);
    }

    void Update(){
    //Loop through ALL pipes and check each position
    }

This is definitely the harder way though. It would be easier just to attach a script to each pipe object that checks the pipes position and then destroys itself once it is far enough away

public class PipeDestroy : Monobehavior{ //Attach this to your pipe prefab

    void Update(){
        if(transform.position.x < -14) Destroy(gameObject);
    }
}