🔫Projectile Spawner
v1.0
Last updated
v1.0
Last updated
This is a thing that spawns Projectiles. It could be a gun or other object, it could be something like a turret in your game, or it could be a virtual object on your player character which can spawn all sorts of projectiles.
Add a ProjectileSpawner
component to the object you wish to spawn projectiles.
The custom inspector organizes the Projectile Spawner options into a few categories. Toggle on the "Show Help Boxes" option to see more details inside the Inspector.
This is where we set up all the required and some optional settings.
The Projectiles spawned by this Spawner will interact with the layers you select here. Each Projectile can override this layer as well, though in most cases, we expect you would not override the value set on the Spawner.
This is the target which Projectiles will inherit at spawn. You can update this at runtime as well.
While each projectile will inherit the target when they are created, the projectiles can individually have their targets updated while they are active.
This is the list of available projectiles. You need to have at least one projectile. Check the code for details on how to set the active projectile, and replace projectiles in the list with new ones.
The Observers you add here will be copied to all projectiles created by this Spawner. This enables new hooks for your project.
In the demo scenes, the Demo Actor Observer
is included, which enables the player Actor
to know whenever one of their projectiles collides with a target. This is how damage is sent from the player Actor
to the target Actor
.
There are multiple ways to hook into the Projectile Factory code -- you may wish to use the Events to handle damage connections instead.
Each Projectile Spawner can have any number of Spawn Points. Each point includes the transform of the "spawn point" itself, as well as a rotating and tilting transform, which may be utilized by some of the Spawn Behaviors.
If you have more than one Spawn Point, use a Spawn Point Manager class to control how the Spawn Points are selected. This provides a tremendous amount of control in order to create any kind of spawning behavior you'd like.
Each spawner can include a default Trajectory Behavior to used when the trajectory is active. Individual Projectiles can override this, which is useful when the Projectile behavior is more unique.
Trajectories are an important player experience for many games, and provide a lot of information to the player. Projectile Factory ships with a number of game-ready trajectories, but you may wish to create your own, to provide your players the best experience for your project.
When true, the Trajectory will show even if no projectile is currently selected in the spawner.
These values are set at runtime.
When true, the trajectory will always show.
When true, the trajectory should show.
These UnityEvents
are called throughout the Projectile Spawners lifecycle. Use these to hook into the Projectile Factory system from your classes.
The Demo Controller use the OnNewProjectileSelected
event. If the "fire" button (mouse button in the demo) is down when this event is triggered, the controller will initiatiate the "Spawn" immediately, which allows for continuous firing even while the projectiles change.
OnLaunch
Called whenever the Projectile Spawner starts the Launch
coroutine. This is not called for each individual projectile that is spawned. Use the Projectile Events for that.
OnProjectileStopped
This is called when the Launch
coroutine is stopped.
OnShowTrajectoryStart
This event is called whenever the Trajectory starts to show.
OnShowTrajectoryStop
This event is called whenever the Trajectory stops showing.
OnNewProjectileSelected<Projectile, Projectile>
Whenever a new projectile is selected, this event will be called. This event has a <Projectile, Projectile>
signature, which includes the New Projectile and the Old Projectile (in that order).
OnNewSpawnPointSelected<SpawnPoint, SpawnPoint>
This is called whenever a new Spawn Point is selected. This event has a <SpawnPoint, SpawnPoint>
signature, which includes the New Spawn Point and the Old Spawn Point (in that order).
These events are called from the Projectile during the lifecycle of the projectile.
Projectiles can not directly have Unity Events
added from in-scene objects. Instead, add them here on the Projectile Spawner. The events will be copied to each projectile when the projectile is spawned.
OnLaunch<Projectile>
)Called when the projectile is launched.
OnProjectileStopped<Projectile>
This is called when the Projectile Spawner assigned to this Projectile stops firing.
OnReturnToPool<Projectile>
& OnGetFromPool<Projectile>
These are called when the projectile is returned to the pool or retreieved from the pool respectively.
OnCollisionEnter<Projectile, Collision, GameObject, Vector3>
& Exit
, Stay
The collision events pass in the projectile, as well as the Collision
, the GameObject
collided with, and the Vector3
point of contact. Note that depending on how the collision was triggered, those values may be null
or default
.
OnTriggerEnter<Projectile, Collider, GameObject, Vector3>
& Exit
, Stay
The trigger events pass in the projectile, as well as the Collider
, the GameObject
collided with, and the Vector3
closest contact point. Note that depending on how the trigger was triggered, those values may be null
or default
.
OnDoDestroy<Projectile>
This is called when the Projectile is destroyed via the InvokeDestroy
method on Projectile.cs
.
OnDoEnable<Projectile>
& OnDoDisable<Projectile>
These are called when the DoEnable
and DoDisable
methods are called. They may be called from the normal OnEnable
and OnDisable
methods, or via other mechanisms.
OnReset<Projectile>
This event is called at the end of the ResetProjectile
method. While this method may be called in other ways, ProjectilePoolManager
will call this during the ReturnProjectile
cycle -- this is when the projectile is being put back into the pool.
OnProjectileSpawnerSet<ProjectileSpawner, Projectile>
This event is called when the assigned ProjectileSpawner
is set via the SetProjectileSpawner
method. This happens at the start of the lifecycle, but may also happen if you proactively change the assigned ProjectileSpawner
.