I was wondering if anyone could help me with this.
I spawn a cube on mouse click at the origin i.e. [0,0,0]. I want to be able to spawn another cube and so on at [2f,0,0] in the x axis while still keeping the old cube at [0,0,0].
public GameObject Cube;
List<Cube> ball = new List<Cube>();
public float splitAngle = 30.0f;
// Use this for initialization
void Start ()
{
Instantiate(Cube, new Vector3(0, 0, 0), Quaternion.identity);
spawnPrefab ();
}
// Update is called once per frame
void Update ()
{
if (Input.GetMouseButtonDown (0))
{
for (int i = 0; i < 10; i++)
{
Instantiate(Cube, new Vector3(i * 1.0F, 0, 0), Quaternion.identity);
}
}
}
public void spawnPrefab()
{
}
}
I’ll really appreciate the help as I’m stumped right now.
Thanks for replying. But I dont want it to spawn at a cursor location. I want it to spawn on an axis. I just want the mouse click to enable the spawn to happen.
“cursorLocation” is just the name of the variable. Set it to whatever you like, move it however you like, moving it once per spawn, if I understand your original question properly.
At the function where you Instantiate the new prefab at the cursorLocation, then you advance the cursorLocation to the next place you want the next one to spawn.
That way the next time you call the function that does that, it will automatically appear at the next location, and so on.