Respawner
The Respawner component will respawn the object when the object dies or is destroyed. The object can either spawn at the current location, the starting location, or can use the spawn point system to determine where to spawn.
Inspected Fields
Positioning Mode
Specifies the location that the object should spawn:
- None: The object will not change locations when spawning.
- Start Location: The object will spawn in the same location as the object started in.
- Spawn Point: The object will use the Spawn Point system to determine where to spawn.
Grouping
The grouping index to use when spawning to a spawn point. The grouping will be ignored if the value is -1. Groupings can be used in the case of having multiple teams. As an example, consider a team deathmatch game where the red team has a grouping value of 0 and the blue team has a value of 1. When a player on the red team goes to spawn only the Spawn Points with a grouping value of 0 will be used to decide if the player can spawn in that location.
Min Respawn Time
The minimum amount of time before the object respawns after death or after being disabled.
Max Respawn Time
The maximum amount of time before the object respawns after death or being disabled.
Schedule Respawn On Death
Should a respawn be scheduled when the object dies?
Schedule Respawn On Disable
Should a respawn be scheduled when the component is disabled?
Respawn Audio Clip Set
A set of AudioClips which can be played when the object is respawned.
Events
When the object respawn occurs the “OnRespawn” event will be sent from the built-in Event System. A corresponding Unity event will also be sent. The following example will subscribe to this event from a new component:
using UnityEngine; using Opsive.Shared.Events; public class MyObject : MonoBehaviour { /// <summary> /// Initialize the default values. /// </summary> public void Awake() { EventHandler.RegisterEvent(gameObject, "OnRespawn", OnRespawn); } /// <summary> /// The object has respawned. /// </summary> private void OnRespawn() { Debug.Log(name + " Respawned."); } /// <summary> /// The GameObject has been destroyed. /// </summary> public void OnDestroy() { EventHandler.UnregisterEvent(gameObject, "OnRespawn", OnRespawn); } }