How can i Instantiate object and make the object to be Instantiate in the center of another object ?

using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class InstantiateUnits : MonoBehaviour
{
    public Transform Range;
    public Transform unitToInstantiate;
    public int numberOfUnits;

    // Use this for initialization
    void Start ()
    {
        for (int i = 0; i < numberOfUnits; i++)
        {
            Instantiate(unitToInstantiate, new Vector3(i * 2.0F, 0, 0), Quaternion.identity);
            Instantiate(Range, new Vector3(i * 2.0F, 0, 0), Quaternion.identity);
            unitToInstantiate.parent = Range;
        }
    }
	
	// Update is called once per frame
	void Update ()
    {
		
	}
}

I want that each created unitToInstantiate to be in the center of created Range.

Range is a GameObject and unitToInstantiate is a Prefab.
But i’m getting exception on the line:

Instantiate(Range, new Vector3(i * 2.0F, 0, 0), Quaternion.identity);

InvalidCastException: Cannot cast from source type to destination type.
UnityEngine.Object.Instantiate[Transform] (UnityEngine.Transform original, Vector3 position, Quaternion rotation)

And i’m also not sure that making the unitToInstantiate parent of the Range will create them in the middle of the Range. So i have two problems.

First you need to save the Instantiated object as a variable, then you set it to be the child of the range object. Last, you make the local position of range to be in the center.

GameObject unitInstantiated = Instantiate(unitToInstantiate, new Vector3(i * 2.0F, 0, 0), Quaternion.identity);
             GameObject rangeInstantiated = Instantiate(Range, new Vector3(i * 2.0F, 0, 0), Quaternion.identity);
             unitInstantiated.SetParent(rangeInstantiated.transform);
             unityInstantiated.transform.localPostion = Vector3.zero;