Difference between revisions of "RandomPrefabSpawner"

From Headbone Creative
Jump to: navigation, search
(Initial page, includes API information and categories)

Revision as of 16:47, 20 April 2013

This script allows the game designer to easily spawn prefabs randomly around the object it's attached to. It provides a custom editor interface with buttons to allow the designer to clear and regenerate the random prefabs easily. Additionally, the RNG can be sent a seed value to re-create the same random field each time.

Contents

Public Variables

mode : GenerationMode

This determines along what axis the objects are placed. It may have the following values:

X

This places objects linearly along the X axis.

Y

This places objects linearly along the Y axis.

Z

This places objects linearly along the Z axis.

X_Y

This places objects in a circle on the X, Y plane.

X_Z

This places objects in a circle on the X, Z plane.

X_Y_Z

This places objects inside a sphere.

seed : int

This will be set to seed the random number generator before prefabs are spawned, unless randomizeSeed is set to true.

randomizeSeed : bool

If this is true, the seed will be set to the current time when UpdateField () is called.

numToGenerate : int

This is how many prefabs will be spawned.

radius : float

This is how large of an area the prefabs will cover. This is shown in the Scene view of the Unity Editor as a green wireframe sphere when this object is selected.

prefabs : List<GameObject>

This is the list of all of the prefabs that will be spawned.

Public Functions

void ClearField ()

This clears the field by destroying all child objects of the object.

void UpdateField ()

This spawns the prefabs randomly around the current object, as defined by the public variables. The prefabs that are spawned are set as child objects of the object this script is attached to, so the entire thing can be moved around the scene easily.

Personal tools
Namespaces

Variants
Actions
Navigation
Toolbox