Hi, I forgot to mention this sooner that I'm new in coding and last time posted on asking for how to spawn position to which I successfully done. But, now need help in wanting the spawning prefabs located within a rectangle area in unity. Here are ideas of want I mean from these web links. how to create a spawn point within shape area for unity
https://www.google.com/search?q=how+to+create+a+spawn+point+within+shape+area+for+unity&tbm=isch&ved=2ahUKEwjis6XB27DzAhUzqHIEHbL2DKkQ2-cCegQIABAA&oq=how+to+create+a+spawn+point+within+shape+area+for+unity&gs_lcp=CgNpbWcQA1Ck58kCWOD1yQJg0v7JAmgAcAB4AIABowGIAfcEkgEDNC4ymAEAoAEBqgELZ3dzLXdpei1pbWfAAQE&sclient=img&ei=3-1aYaLIJbPQytMPsu2zyAo&bih=625&biw=1366&hl=en Also here is the random spawn script that I made if needed to apply where for the rectangle script to go to.
public GameObject objectToSpawn;
public GameObject parent;
public int numberToSpawn;
public int limit = 15;
public float rate;
float spawnTimer;
// Start is called before the first frame update
void Start()
{
spawnTimer = rate;
}
void Update()
{
if (parent.transform.childCount < limit)
{
spawnTimer -= Time.deltaTime;
if (spawnTimer <= 0f)
{
for (int i = 0; i < numberToSpawn; i++)
{
Instantiate(objectToSpawn, new Vector3(this.transform.position.x + GetModifier(), this.transform.position.y + GetModifier())
, Quaternion.identity, parent.transform);
}
spawnTimer = rate;
}
}
}
float GetModifier()
{
float modifier = Random.Range(-10.5f, 10.5f);
if (Random.Range(0, 2) > 0)
return -modifier;
else
return modifier;
}
}