C# Класс Stochasteroid, GameProject

Stochasteroid is a script for creating randomized asteroid fields. Simply place this script on a cube GameObject named "StochasteroidPen," set the asteroid scale, rotation, velocity, count, select desired trajectories, and assign asteroid prefabs and the class will automatically fill the cube with randomly placed asteroids. Each asteroid requires a rigid body to realistically simulate motion. Each asteroid is generated randomly by selecting values within the given ranges. When an asteroid reaches the edge of the cube it is automatically respawned on a new trajectory.
Наследование: MonoBehaviour
Показать файл Открыть проект

Открытые свойства

Свойство Тип Описание
asteroidCount int
asteroidMaxRotation int
asteroidMaxScale int
asteroidMaxVelocity int
asteroidMinRotation int
asteroidMinScale int
asteroidMinVelocity int
asteroidTemplates List
negativeXTrajectory bool
negativeYTrajectory bool
negativeZTrajectory bool
positiveXTrajectory bool
positiveYTrajectory bool
positiveZTrajectory bool

Открытые методы

Метод Описание
Start ( ) : void

Initialize script.

Update ( ) : void

Per frame update. Performs asteroid update.

Приватные методы

Метод Описание
CreateAsteroid ( ) : GameObject

Creates a new Asteroid object randomly from the avaiable templates.

IsAsteroidInCube ( GameObject asteroid ) : bool

Checks if asteroid is in cube.

PlaceAsteroid ( GameObject asteroid ) : void

Picks a random trajectory through the cube of those allowed by the script parameters and applies a random force and rotation on the asteroid in that direction.

RandomFacePoint ( ) : Vector3

Randomly selects a point from one of the six cube faces. If a selected face is one that is deactivated by the trajectory params for the script then selects again.

UpdateAsteroid ( GameObject asteroid ) : void

Performs asteroid frame update. We use physics to move asteroids so this function merely picks a new trajectory for the asteroid if we reach the edge of the cube.

Описание методов

Start() публичный Метод

Initialize script.
public Start ( ) : void
Результат void

Update() публичный Метод

Per frame update. Performs asteroid update.
public Update ( ) : void
Результат void

Описание свойств

asteroidCount публичное свойство

The number of asteroids to spawn.
public int asteroidCount
Результат int

asteroidMaxRotation публичное свойство

The maximum rotation that a particular asteroid may exhibit. This is an upper bound and is unitless. The actual value will be selected at random.
public int asteroidMaxRotation
Результат int

asteroidMaxScale публичное свойство

The maximum scale factor of each asteroid. Actual value is randomly selected.
public int asteroidMaxScale
Результат int

asteroidMaxVelocity публичное свойство

The max velocity for an asteroid. This velocity is a multiplier and is unitless.
public int asteroidMaxVelocity
Результат int

asteroidMinRotation публичное свойство

The minimum amount of rotation for a particular asteroid. This is a lower bound and is unitless. The actual value will be selected at random.
public int asteroidMinRotation
Результат int

asteroidMinScale публичное свойство

The minimum scale factor of each asteroid. 1.0 is the model's initial size as imported by Unity. Actual value is randomly selected.
public int asteroidMinScale
Результат int

asteroidMinVelocity публичное свойство

The minimum velocity for an asteroid. This velocity is simply a multiplier and is unitless.
public int asteroidMinVelocity
Результат int

asteroidTemplates публичное свойство

A list of GameObjects that will act as randomly chosen templates for the asteroids.
public List asteroidTemplates
Результат List

negativeXTrajectory публичное свойство

Enables asteroids with trajectories beginning or ending on the negative X pane of the cube.
public bool negativeXTrajectory
Результат bool

negativeYTrajectory публичное свойство

Enables asteroids with trajectories beginning or ending on the negative Y pane of the cube.
public bool negativeYTrajectory
Результат bool

negativeZTrajectory публичное свойство

Enables asteroids with trajectories beginning or ending on the negative Z pane of the cube.
public bool negativeZTrajectory
Результат bool

positiveXTrajectory публичное свойство

Enables asteroids with trajectories beginning or ending on the positive X pane of the cube.
public bool positiveXTrajectory
Результат bool

positiveYTrajectory публичное свойство

Enables asteroids with trajectories beginning or ending on the positive Y pane of the cube.
public bool positiveYTrajectory
Результат bool

positiveZTrajectory публичное свойство

Enables asteroids with trajectories beginning or ending on the positive Z pane of the cube.
public bool positiveZTrajectory
Результат bool