- Home /
How do you make a spawner block?
To be more specific, I would like to make a block which will spawn other pre-defined blocks within a certain radius, and I would like to apply limits to what radius certain blocks can spawn..For example, like in minecraft, diamonds only spawn from levels 5 till 15, I would like to do something similar for the blocks which will spawn around the central spawner block. Any help will be appreciated :) Thanks in advance!
Answer by dorpeleg · Sep 16, 2012 at 02:05 PM
the following code is written in C#.
this code wasn't tested.
this code is not complete or perfect. you might need to work on it a bit.
this code should be on your spawner block.
you should drag the block prefabs into their right locations in the inspector.
the code will only spawn one block. you will have to make it spawn more on your own
public GameObject DirtBlock,StoneBlock,DiamondBlock; private Vector3 Position; public float RndMin,RndMax; void Start() { RndMin = this.transform.position.y - 10.0f; //the closest location to the spawner blcok RndMax = this.transform.position.y - 70.0f; //the farthest location from the spawner block position = new Vector3(0, Random.Range(RndMin, RndMax),0); Instantiate (DiamondBlock, position, Quaternion.identity); }
is it possible to give me the same thing in javascript please?
sorry im not to familiar with js. go here: http://docs.unity3d.com/Documentation/ScriptReference/index.html just look st some of the codes in their js format. shouldn't be hard to change.
Your answer
Follow this Question
Related Questions
Generate new blocks to land on 1 Answer
Choosing given numbers randomly 1 Answer
How to generate random pickup items on EasyRoads3D? 2 Answers
Generating objects randomly, only one will Instantiate 0 Answers
How to make levels spawn randomly? 0 Answers