[Solved] Instantiate Object Along Z Axis?

using UnityEngine;
using System.Collections;
   
public class SpawnerInParent : MonoBehaviour {

    public GameObject[] testObject;
    public float xRange = 1.0f;
    public float zRange = 1.0f;
    public float minSpawnTime = 1.0f;
    public float maxSpawnTime = 10.0f;

    // Use this for initialization
    public void Start ()
         {
        Invoke ("SpawnItem", Random.Range (minSpawnTime, maxSpawnTime));
    }
   
    // Update is called once per frame
     void SpawnItem ()
    {
        float xOffset = Random.Range (-xRange, xRange);
        float zOffset = Random.Range (-zRange, zRange);
        int spawnObjectIndex = Random.Range(0, testObject.Length);
        GameObject goInst = (GameObject) Instantiate (testObject [spawnObjectIndex], transform.position + new Vector3 (xOffset, zOffset, 0.0f), testObject [spawnObjectIndex].transform.rotation);
        goInst.transform.parent = transform;
        Invoke ("SpawnItem", Random.Range (minSpawnTime, maxSpawnTime));
    }
}

I was using this code to spawn along x and y axis worked perfectly. Now I need it to spawn along x and z axis…So I changed y axis to z but it still spawns along the y axis? Help please?

line 24. you’ve got ur zOffset info in the y-part of the new vector

1 Like

Great works great now. I also noticed this is your first post. Welcome to Unity I feel honoured your first post was helping me lol :slight_smile: Thank you.

hehe, thanks. pleasure is mine :slight_smile: