Hello guys.
public class SpawnMeteoritov : MonoBehaviour {
public GameObject ObjectToSpawn;
public float RateOfSpawn = 1f;
private float nextSpawn = 0f;
void Update()
{
if (Time.time > nextSpawn)
{
nextSpawn = Time.time + RateOfSpawn;
Vector2 rndPosWithin;
rndPosWithin = new Vector2(Random.Range(-1f, 1f), Random.Range(-1f, 1f));
rndPosWithin = transform.TransformPoint(rndPosWithin * .5f);
Instantiate(ObjectToSpawn, rndPosWithin, transform.rotation);
}
}
}
My script making this. I have 1 game objects(CUBE) when i put my script in to this gameobject(CUBE), he will randomly spawn next game objects in this (CUBE) every 5seconds(example).
And my script makes it that when I start the script, it spawns in every (CUBE-we have 4 CUBES) every 5 seconds another object. This means that (4 CUBES) spawns 4 game objects. And I need to spawn only 1(i must make from this 4 CUBES only 1 GameObject, where next game objects will be randomly spawn).
Check screenshoot
Screenshoot:
You can see that every 5 seconds on these 2 cubes, they spawn 2 game objects. I need on these 2 cubes, spawning 1 game object.
Thank you for every answer.