This is the tenth tutorial in a series about Object Management. It adds a satellite behavior, which introduces relationships between shapes.

This tutorial is made with Unity 2017.4.12f1.

At this point the old design of the SpawnZone.SpawnShape method is no longer appropriate. First, it no longer needs to return a shape. Second, it no longer needs to be restricted to spawning a single shape, as it currently spawns two per invocation. So change it to void SpawnShapes .

This is also true in Game.LoadGame , so we must no longer explicitly add loaded shapes to the list. To do so would result in duplicate entries.

We'll make ShapeFactory.Get responsible for adding each shape to Game . This makes ShapeFactory aware of Game , but also makes it so that we never need to worry about whether a shape has been added to Game yet, assuming that all shapes are retrieved via a factory.

We could have SpawnShape return a list of shapes, but the goal is to get the shapes added to the shape list when they are spawned, no matter when or where that happens. We can do that by turning the responsibility around, and once again make Game available via a static Instance property. Then it's up to whoever spawns a shape to pass it to Game .

The idea of SpawnShape was that it brings a new shape into the game, which is returned so that Game can add it to its list of shapes. That still happens for the regular shape, but the satellite shape isn't added to the list, which means that it doesn't get updated and remains frozen.

We'll also have to give the satellite a color, the same way we give the focus shape a color. Put the relevant code in a SetupColor method so we can reuse it.

We won't create a real satellite just yet. For now, we make the satellite half the size of the focus shape, position it one unit above it, and make it move upwards.

To spawn a satellite we'll add a CreateSatelliteFor method to SpawnZone , with a parameter for the focal shape. The focal shape is what the satellite will orbit. We could use separate factories for the satellites, but we'll simply use the same factories for the regular shape to spawn a random one and give it an arbitrary rotation.

In this tutorial we're going to create a behavior that lets a shape orbit another shape, like a satellite. We'll decide whether a shape has a satellite when it is spawned. If so, then we'll also spawn its satellite. This means that each time that we spawn a shape we might end up with two new shapes instead of always one.

Satellite Behavior