How to tell the number of instantiated object

Hey guys,
In my project I instantiate a GameObject everytime I hit right mouse button.
At the same moment I am creating an listelement in my flexible list.
I want to control a specific GameObject with the corresponding listelement e.g delete the second one called “Schweißnaht 2”.
The GameObject (sphere) and the listelement are both prefabs.

How can i connect them so I can control the GameObjects within the corresponding listelement?

Kind regards,
Stefan

  //creating a listelement
                        display = (GameObject)Instantiate(ItemDisplayPrefab);
    
                        //target in hierarchy
                        display.transform.SetParent(targetTransform, false);
    
                        //Change name
                        display.name = "Schweißnahtelement " + SchweißnahtZahl ;
                        Debug.Log(Nahtzahl);

//Creating an element
void CreateFirstElement(Vector3 mousePosition)
    {
        //create object
        newObject = Instantiate(Kugel, mousePosition, transform.rotation);
        
        //name object and increase counter
        newObject.name = "Punkt " + Counter;
        Counter++;

        //Rotation des Objektes auslesen
        mousrot = newObject.transform.localEulerAngles;

        // Which type is it
        Typ = ButtonChangeSphereType.Type;

//add coordinates to list
        Trajektory.Add(new Trajektory(mousposneu.x, mousposneu.y, mousposneu.z, mousrot.x, mousrot.y, mousrot.z, Typ));

       

        //target in hierarchy
        newObject.transform.parent = newContainer.transform;
        
    }

It sounds like you want to create a struct that holds both your trejectory information and a refrence to the corresponding gameObject. You then have a list of those structs that you can add to whenever you Instanciate a new ball.

Hey Goat-Boy, thanks for the answer :slight_smile:
I added two lines of code:

 //Create Object for listelement 
                    display = (GameObject)Instantiate(ItemDisplayPrefab);

                    //target
                    display.transform.SetParent(targetTransform, false);



                    **//giving attribute Pos the acutal weld-number
                    var thescript = display.GetComponent<ButtonActionManager>();
                    thescript.Pos = SchweißnahtZahl;**


            
                    //change Name
                    display.name = "Schweißnahtelement " + SchweißnahtZahl ;