Projectile Spawner Code

v1.0

Like most of the classes in Projectile Factory, the ProjectileSpawner class is extensible, with most properties and methods virtual.

This means you can create your own custom ProjectileSpawner class to override the methods, and add new logic specific to your game and requirements.

Properties

The ProjectileSpawner has a number of (mostly virtual) properties ready to be used.

public virtual Transform SpawnTransform
public virtual Vector3 SpawnPosition
public virtual Vector3 SpawnRotation
public virtual Vector3 SpawnForward
public virtual Vector3 SpawnForwardPosition
public virtual Vector3 SpawnForwardDistance(float distance)
public virtual Transform RotatingTransform
public virtual Transform TiltingTransform
public virtual GameObject ProjectileObject // Gets the active Projectile
public virtual Projectile Projectile // Projectile class from the active projectile
public bool ShowTrajectory // true if we are currently showing the pre-launch trajectory

Notable Methods

Check the class itself for all the methods. I'll cover the most interesting ones here.

StopProjectile()

Call this to stop the current projectile being spawned. This also invokes the OnProjectileStopped event.

In the demo scene, the TryStopShooting() method on DemoController.cs calls this method to stop the projectiles that repeat, such as the machine gun.

SpawnProjectile()

Call this to spawn the projectile.

The demo scene DemoController.cs calls this from the TryShoot() method.

Toggle and Set Show Trajectory

ToggleAlwaysShowTrajectory() and ToggleShowTrajectory() will both toggle those values.

SetAlwaysShowTrajectory() and SetShowTrajectory() will set those true or false to the value you provide.

Previous and Next Projectile

The NextProjectile() and PreviousProjectile() methods can be used to cycle through the available Projectiles in the List.

Set Projectile

There are two SetProjectile() methods. One takes in the index of the projectile, the other takes in a Projectile GameObject, and if found in the list, will set the active Projectile to the one that matches.

AddToCollisionMask() and RemoveFromCollisionMask

Pass a LayerMask into these methods to either Add or Remove those values.

Last updated