Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/jacobsteves/dynamic-object-spawner
An object spawner for Unity to enhance CPU efficiency.
https://github.com/jacobsteves/dynamic-object-spawner
Last synced: about 2 months ago
JSON representation
An object spawner for Unity to enhance CPU efficiency.
- Host: GitHub
- URL: https://github.com/jacobsteves/dynamic-object-spawner
- Owner: jacobsteves
- License: mit
- Created: 2018-03-10T00:42:59.000Z (almost 7 years ago)
- Default Branch: master
- Last Pushed: 2018-03-12T00:31:23.000Z (almost 7 years ago)
- Last Synced: 2023-11-08T19:49:43.243Z (about 1 year ago)
- Language: C#
- Homepage:
- Size: 12.8 MB
- Stars: 5
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# Dynamic Object Spawner
The Dynamic Object Spawner was made for performance enhancement so that GameObjects or enemies that are not seen or not in use do not appear in the game. This is more efficient for CPU usage and can allow more objects to appear be in your scene, allowing the developer to focus more on intricate AI.
Demo |
:-------------------------:|
![Demo gif](Demo/demo.gif) |
The number of destroyed objects was set to all but one, and as soon as the respawn time was reached and the player re-entered the spawn trigger, all previously destroyed objects respawned.## Usage
For an example, if you are spawning enemies, call `ObjectSpawner.cs -> incrementObjectsDestroyed ()` everytime an enemy dies. This method ensures that objects will not spawn back until the respawn time has been fufilled. Then, a body will remain in the game but the spawner will still keep track of the objects alive.
If you simply destroy the object, then the spawner assumes the object is some type of renewable resource, so it will spawn the object back in whenever the player comes within distance.
## Getting Started
### Prerequisites
- [Unity](https://unity3d.com/)
- A Built [NavMesh](https://docs.unity3d.com/Manual/nav-BuildingNavMesh.html) in your scene### Installation
1. Add `Spawner/ObjectSpawner.cs` to your project.
2. Ensure your player is tagged `Player` or change this code in `ObjectSpawner.cs` if you want your player to be named something else
3. Ensure your player has some Collider (with `Is Trigger` unchecked) and a Rigidbody.
4. Add `Spawner/ObjectSpawner.prefab` to your project, and update the Script settings in Unity's Inspector window to use the prefab you want to be spawned in. Read the next section for more information.## Customization
Unity's Inspector Window |
:-------------------------------:|
![Inspector](Demo/inspector.png) |
- Spawn Radius: The radius that you want the objects to spawn within. The objects will spawn in random locations between the radius and the ObjectSpawner.
- Trigger Radius: The radius the trigger extends to. When the players distance to the the ObjectSpawner is within the `Trigger Radius`, the objects are spawned in. When the player leaves this radius, the Objects are destroyed from the scene until the player re-enters the radius.
- Max Game Objects: How many objects the Spawner can spawn in.
- Seconds To Respawn: How long until destroyed Game Objects respawn. The objects will never respawn while the player is within the `Trigger Radius`. The player must leave the `Trigger Radius` and then as soon as the player goes back within the `Trigger Radius`, the spawner checks how many objects to spawn back in by determining if objects have been destroyed for longer than `Seconds to Respawn`
- Prefab: A prefab of the Game Object you want to spawn in.
- Cur Game Objects: A list of the Game Objects the spawner currently holds. Everytime an object is spawned, ObjectSpawner holds a reference to its location within this list.## License
This project is licensed under the MIT License - see the [LICENSE](LICENSE) file for details