I just started in Unity, I'm trying to make an Object Spawner but it only makes one

Hey, so I’m INSANELY new to coding and C#… I’m working on a project, and I’m trying to make an object spawner. When I hit play on my game though, it only makes that object once. I used this same code on a different object and it works fine (this is also not my code, and probably more complicated than what I would need for this).
Here’s the code I’m using:

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

public class Light : MonoBehaviour
{
public GameObject[ ] ob;
public Transform campos;
// Start is called before the first frame update
void Start()
{
LightMaker();
}

// Update is called once per frame
void Update()
{

}

void LightMaker()
{
GameObject clone= (GameObject) Instantiate (ob[Random.Range(0,ob.Length)], transform.position, Quaternion.identity);
clone.name=“Quad(1)”;
float xx=Random.Range(1,5);
Invoke(“LightMaker”,xx);
}
}

Are you sure they’re not just overlapping each other? They’ll all spawn in the same position with this code.

1 Like

That’s probably it, honestly. How do I change the position? (Sorry about the dumb questions)

After instantiating set the position of the ‘clone’ object like

clone.transform.position = new Vector(x, y, z);

Or just pass in a Vector3 in the Instantiate function where you now pass in transform.position.

1 Like