In Unity:
- Create a new scene
- Add a GameObject called Manager
- Add a GameObject called Spawner
- Add a GameObject called Despawner
- Add a Camera, set to main
- Add a Quad, rotate it 90 deg around X so that it forms a ground plane
- Create a new script called Manager.cs
- Create a new script called Spawner.cs
- Create a new script called Despawner.cs
- Create a new script called Entity.cs
- Create a default cube. Make sure it has a collider.
- Add the Entity.cs to the cube
- Create a prefab of the cube
- Remove the cube from the scene
Fill in the contents of the scripts with the scripts attached to this gist. Recompile, and add the scripts to their respective GameObject and add the references as necessary.
Finally, press Play.
Click the left mouse button to spawn, and right mouse button to despawn.