Hello and thanks for stopping by, here’s my scene starting point :
I’m trying to instantiate prefabs in my scene and make them spawn around the initial prefab
(the square in the image).
I’ve got a somewhat working code that does instantiate the prefab under it, and I now know how to make it spawn around. The problem is that it’s not scalable : I would have to write in my code the position of each prefab…
Any ideas on how to do that ?
Thanks for reading.
(Here’s my current code) :
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class Spawning : MonoBehaviour {
public GameObject Tile;
[SerializeField] private int TotalTilesSpawned = 0;
[SerializeField] private float xAxis = 0f;
[SerializeField] private float yAxis = - 2f;
void Update(){
if (Input.GetKeyDown("s")){
Instantiate(Tile, new Vector2 (xAxis, yAxis), transform.rotation);
TotalTilesSpawned += 1;
yAxis -= 2;}
}
}