A class in Root.Township, the global namespace.
Makes a list of child objects bob back and forth and slowly spin, each with its own random offset. Runs in edit mode too.
Constructors
| Member | What it is |
|---|
BobbingController() | Unity makes components itself; use AddComponent or spawn a prefab instead of new. |
Fields
9 private and internal fields
| Member | What it is |
|---|
private float bobbingSpeed | Backing field for BobbingSpeed. |
private float bobbingStrength | Backing field for BobbingStrength. |
private bool isSettingUp | Inspector Setup button. |
private float movementRadius | Radius objects are scattered in by AddObjectToBob. |
private List<Transform> objectsToBob | Transforms being bobbed. |
private List<float> randomOffsets | Sine phase per object. |
private List<Vector3> randomRotationAxis | Spin axis per object. |
private List<float> randomRotationsSpeed | Spin speed per object, 0.1 to 1. |
private float rotationSpeed | Overall spin speed multiplier. |
Properties
| Member | What it is |
|---|
float BobbingSpeed { get; set; } | How fast objects bob. Read and write. |
float BobbingStrength { get; set; } | How far objects bob along local Z. Read and write. |
Methods
| Member | What it is |
|---|
void AddObjectToBob(Transform objectToBob) | Adds an object, puts it at a random spot within movementRadius with a random rotation, and turns bobbing on. |
void ClearObjects() | Removes all objects and offsets and turns the component off. |
6 private and internal methods
| Member | What it is |
|---|
private void Awake() | Turns itself off if there is nothing to bob and sets up the random offsets. |
private void CreateNewRandomOffsets() | Adds a random phase, spin axis and spin speed for one object. |
private void OnDrawGizmosSelected() | Editor: draws movementRadius as a wire sphere. |
private void OnValidate() | Editor: rebuilds offsets when the Setup button is pressed. |
private void SetupOffsets() | Rebuilds the random offsets for every object in the list. |
private void Update() | Moves each object's local Z on a sine wave and spins it. Drops destroyed objects and turns off when empty. |
Used in
Members of other types that take, return or hold a BobbingController: