# In sequence position game objects

For my 2d game I want to post 10 heart objects in sequence on after other.
For this I write following code but it does not work for me. So I want some suggestion in this.

``````    private const float HEART_SIZE = 45f;
public GameObject heartLightPrefab, heartDarkPrefab;

void Start()
{
float startX = 0f,startY=0f;
for (int i = 0; i < Constants.TOTAL_HEARTS; i++)
{
Vector3 heartPosition = new Vector3(startX,startY,0f);
GameObject heartObject =  Instantiate(heartLightPrefab, heartPosition, Quaternion.identity) as GameObject;
heartObject.transform.parent = gameObject.transform;
heartPosition = Camera.main.ScreenToWorldPoint(heartPosition);
heartObject.transform.localPosition = heartPosition;
startX += HEART_SIZE;
}

}
``````

Using above code objects start generation from left side of the camera and finishes before it get chance to view in camera.

Also I am trying to position object based on relative to other collection object which is empty game object.

EDIT :
At present objects positioned

Place an object at the left side of the screen, with z = -20; another one at the right side also with z = -20. Check their x´s, the difference is the width of your screen in world coordinates at a that certain z. Divide it by 10, and that should be the value of HEART_SIZE.

But as I said in the comments, I would do that in world coordinates directly, which are much easier to handle. That should be something like this:

``````    private const float HEART_SIZE = 45f;
public GameObject heartLightPrefab, heartDarkPrefab;

void Start()
{
float startX = 0f,startY=0f;
for (int i = -Constants.TOTAL_HEARTS/2; i < Constants.TOTAL_HEARTS/2; i++)
{
GameObject heartObject =  (GameObject) Instantiate(heartLightPrefab);
heartObject.transform.parent = gameObject.transform;
heartObject.transform.localPosition = new Vector3(i*HEART_SIZE,0,0);
}

gameObject.transform.position = whereverYouWant;
}
``````