Transform child object over time and then destroy it.

I have a parent object which contains a bunch of instantiated children

 gameObjectChild = Instantiate(Resources.Load(spawnObjName), pos, Quaternion.identity) as GameObject;
   = "child" + objectName++;
            gameObjectChild.transform.SetParent(parent.transform, true);

Parent is transforming with his children each time the button is pressed.

GameObject.Find("parent").transform.position += new Vector3(0, -0.94f, 0);

Now I wish to move over time by X axe and then destroy a child object each time the button is pressed.
I am able to destroy it with this:

                    Destroy(GameObject.Find("child" + destroyObjectName++), 0.02f);

Unfortunately I can’t menage to transform it over time properly.
I tried with this, but it just messes everything up.

GameObject.Find("child" + destroyObjectName++).transform.locaposition += new Vector3(1, 0, 0);

Is this the right approach to do that? Any ideas? Thanks!

For starters

 gameObjectChild.transform.SetParent(parent.transform, true);

should be


Instead of referencing the parent constantly, do it once, probably on Awake

// Set a parent object, instead of using find every cycle
function Awake()

//Move parent on click & also destroy a child on click
function OnMouseClick()
{parentObject.transform.position += Vector3(0.0, -0.94f, 0.0);
 // On your old destroy line you had "child" when it should be "parent/child"
 // Because in the hierarchy it should literally be the child of the parent
 // searching your hierarchy for Every object named "child" is bad practice.
 // Also, should not be incrementing variables during a command. Do it before
 Destroy(GameObject.Find("parent/child" + destroyObjectName), 0.02f); } 

//Move over time by x
function Update()
{parentObject.transform.position+=Vector3(1.0*Time.deltaTime, 0.0,0.0);}

This last line is also incorrect, even if the logic was correct too

GameObject.Find("child" + destroyObjectName++).transform.locaposition += new Vector3(1, 0, 0);

Should be

destroyObjectName++; //increment first
GameObject.Find("parent/child" + destroyObjectName).transform.localPosition += Vector3(1.0, 0.0, 0.0);

Hope that helps.