# using an array

**URL:** https://discussions.unity.com/t/using-an-array/786924
**Category:** Scripting
**Tags:** Scripting
**Created:** [April 22, 2020, 6:11am UTC](https://discussions.unity.com/t/using-an-array/786924 "2020-04-22T06:11:05Z")
**Posts on this page:** 5
**Page:** 1

<div class="post-metadata">

### Author: ![faqeerhasnain](https://dub1.discourse-cdn.com/unity/user_avatar/discussions.unity.com/faqeerhasnain/32/482519_2.png) [@faqeerhasnain](https://discussions.unity.com/u/faqeerhasnain)
#### Post date: [April 22, 2020, 6:11am UTC](https://discussions.unity.com/t/using-an-array/786924/1 "2020-04-22T06:11:05Z")

</div>

Hello World,Hope every one is fine  
i ve got an array of objects,want to instantiate those objects one by one,and move them towards a specific point,but when a new object is instantiated i lose control on the previous object and that stops moving.plz help

 ![5746948--604159--Screenshot (254).png](https://europe1.discourse-cdn.com/unity/original/4X/3/b/d/3bdcea270ce787194530a068293efe025eb8e95b.png)

---

<div class="post-metadata">

### Author: ![Dextozz](https://dub1.discourse-cdn.com/unity/user_avatar/discussions.unity.com/dextozz/32/266314_2.png) [@Dextozz](https://discussions.unity.com/u/Dextozz)
#### Post date: [April 22, 2020, 6:57am UTC](https://discussions.unity.com/t/using-an-array/786924/2 "2020-04-22T06:57:44Z")

</div>

Well, whenever you create a new object you are overriding the transformer variable with your new instance of the object. There are a few ways around this, I’ll just name the 2 most obvious ones.

1. Use a list of atransforms to move all of your instantiated objects inside of the update.

```csharp
private List<Transform> atransforms;

private void Update()
{
    foreach(Transform atransform in atransforms)
    {
        // Make sure to delete the global atransform variable first.
        atransform.Translate(-speed, 0, 0);
    }
}

void Thrower()
{
    Transform atransform = Intantiate(gameObjects[i], new Vector(-5, 0, 0), Quaternion.identity);
    atransforms.Add(atransform);
}

```

1. Use Coroutines. This is what I would do. Just convert Update into an endless Coroutine with a yield return null. Then call that coroutine under line 22 while passing in that transform as a parameter.

---

<div class="post-metadata">

### Author: ![faqeerhasnain](https://dub1.discourse-cdn.com/unity/user_avatar/discussions.unity.com/faqeerhasnain/32/482519_2.png) [@faqeerhasnain](https://discussions.unity.com/u/faqeerhasnain)
#### Post date: [April 22, 2020, 11:49am UTC](https://discussions.unity.com/t/using-an-array/786924/3 "2020-04-22T11:49:41Z")

</div>

Ohh man 🙂 Graciousness at its best,thanks alot.

---

<div class="post-metadata">

### Author: ![faqeerhasnain](https://dub1.discourse-cdn.com/unity/user_avatar/discussions.unity.com/faqeerhasnain/32/482519_2.png) [@faqeerhasnain](https://discussions.unity.com/u/faqeerhasnain)
#### Post date: [April 22, 2020, 3:06pm UTC](https://discussions.unity.com/t/using-an-array/786924/4 "2020-04-22T15:06:10Z")

</div>

// Make sure to delete the global atransform variable first.  
Dude what did you mean by this in line 7?

---

<div class="post-metadata">

### Author: ![Dextozz](https://dub1.discourse-cdn.com/unity/user_avatar/discussions.unity.com/dextozz/32/266314_2.png) [@Dextozz](https://discussions.unity.com/u/Dextozz)
#### Post date: [April 22, 2020, 4:00pm UTC](https://discussions.unity.com/t/using-an-array/786924/5 "2020-04-22T16:00:54Z")

</div>

In your original image that you sent, delete line 10. That way there are no conflicts with names.
