How I do spawn prefabs as children of another game object?

I am trying to spawn prefabs as the children of another game object so that object’s transform will affect the spawned prefabs as well. I appreciate any help.

Here is my code so far:

using UnityEngine;
using System.Collections;

public class Spawner : MonoBehaviour
{
public GameObject testObject;
public float xRange = 1.0f;
public float yRange = 1.0f;
public float minSpawnTime = 1.0f;
public float maxSpawnTime = 10.0f;

// Use this for initialization
void Start () 
{
	Invoke ("SpawnItem", Random.Range (minSpawnTime, maxSpawnTime));
}

// Update is called once per frame
void SpawnItem () 
{
	float xOffset = Random.Range (-xRange, xRange);
	float yOffset = Random.Range (-yRange, yRange);
	int spawnObjectIndex = Random.Range (0, testObject.Length);
	Instantiate (testObject [spawnObjectIndex], transform.position + new Vector3 (xOffset, yOffset, 0.0f), testObject [spawnObjectIndex].transform.rotation);
	testObject [spawnObjectIndex].transform.parent = transform; 
	Invoke ("SpawnItem", Random.Range (minSpawnTime, maxSpawnTime));
}

}

If you want your offsets to be affected by the parent position Instantiate them at Vector3.zero instead. Then afterwards apply your offsets to testObject.transform.localPosition

You are assiging the prefab as parent and not the Instance of the object you have spawned, you where close anyways, try whith this tiny modification

using UnityEngine; 
    using System.Collections;
    
    public class Spawner : MonoBehaviour { 
    public GameObject[] testObject; 
    public float xRange = 1.0f; 
    public float yRange = 1.0f; 
    public float minSpawnTime = 1.0f; 
    public float maxSpawnTime = 10.0f;
    
    // Use this for initialization
    void Start () 
    {
        Invoke ("SpawnItem", Random.Range (minSpawnTime, maxSpawnTime));
    }
     
    // Update is called once per frame
    void SpawnItem () 
    {
        float xOffset = Random.Range (-xRange, xRange);
        float yOffset = Random.Range (-yRange, yRange);
        int spawnObjectIndex = Random.Range(0, testObject.Length);
        GameObject goInst = (GameObject) Instantiate (testObject [spawnObjectIndex], transform.position + new Vector3 (xOffset, yOffset, 0.0f), testObject [spawnObjectIndex].transform.rotation);
         goInst.transform.parent = transform;
        Invoke ("SpawnItem", Random.Range (minSpawnTime, maxSpawnTime));
    }
    }