ShotBase Class – as you can see from the inheritance tree above, the ShotBase class is the most fundamental class to all shot behaviors. When creating your own class, it’s important to understand a few of the key methods from this class in order to make the most of your custom variant.
- InitialSet() – this is the first method called when a firing script instantiates a shot and as such becomes a sort of pseudo-constructor. Override to implement custom initializations you might need for your shot. Note that component properties via GetComponent may not be available.
- Start() – marked as virtual so it must be overriden if used in subclasses. Might be necessary when a component property is required but not available via InitialSet().
- Update() / LateUpdate() – typical update methods. Can be overriden in subclasses.
- OnStoppedFiring() – an event which performs an action when the controller that the shot came from stops firing.
- OnEmitterDestroyedDo() – call this method and input a custom callback method which will be called on every frame when the emitter that fired this shot becomes destroyed.
- OnEmitterDestroyedDoOnce() – same as OnEmitterDestroyedDo except it only fires on one frame upon emitter destruction.
- OnEventTimerDo() – fires a custom callback method of your choice on every frame after a set timelimit has been reached.
- OnEventTimerDoRepeat() – fires a custom callback method of your choice after timelimit has been reached, and then resets the timer resulting in repeat actions at regular intervals.
- OnEventTimerDoOnce – same as OnEventTimerDo except it fires on one frame upon reaching the time limit.
- UnParent() – called when the OnStoppedFiring event is raised. It unparents the shot from the emitter if it was parented. Can be overriden for custom functionality.
- OnOutBounds() – called when a bullet reaches past the boundary limit set by the GlobalShotManager. Can be overriden for custom functionality.
- RePoolOrDestroy() – method that’s called whenever a bullet is no longer needed in the scene. The shot is repoooled if it inherits IRePoolable and repooling was enabled in the shot prefab, otherwise it’s destroyed.
- RePool() – performs shot repooling. In some cases, minor customization to this procedure (reseting stats and so forth) are necessary so it can be overriden if required.
- SetSprite() – optional sprite frame replacement given from the Sprite Override in the firing script. Can be overriden if cutomizations are required.