- Home /
How to make a spawner?
So im making this game and i want to have it so that anvils would spawn on the same z and y axis, but the x axis would change (black line). Could someone please help me with the code as i couldn't find it anywhere...
Answer by KittenSnipes · May 06, 2018 at 04:15 AM
Think about it man. You can probably see the same thing in a thousand different scripts. You just need to adjust it to your needs. If you wish to continue developing I recommend watching tutorials and learning how to program yourself or find a programmer in which you can have fun with and play around with different ideas. For now I will give you a decent enough script but I absolutely recommend putting further research in figuring out your next problem.
public GameObject spawnObject;
public Vector3 spawnPoint;
public int maxX = 10;
public int timeTilNextSpawn = 5;
int x = 0;
float timer = 0;
void Start()
{
timer = 0;
spawnPoint.x = x;
}
private void Update()
{
timer += Time.deltaTime;
Spawn();
}
void Spawn()
{
if (timer >= timeTilNextSpawn)
{
x = Random.Range(0, maxX);
spawnPoint.x = x;
Instantiate(spawnObject, spawnPoint, Quaternion.identity);
timer = 0;
}
}
Thanks man. I'm still a begginer i can only write css and html code but I also wanted to make games and am still learning. Yout answer helped thanks again!
No problem I hope this helps you in further development :D