Scripts

This section will give you brief details on scripts used by the turret example. It also important to know that most scripts rely on F3DTimer class and require an instance of such to be present in the scene. Please take your time to examine each script more carefully to fully understand what is happening behind the scene.

CombineChildren

Attach this script as a parent to some game object. The script will then combine the meshes at startup. This is useful as a performance optimization since it is faster to render one big mesh than many small meshes.

F3DAudioController

This script is an example of audio management and playback. What it does is playing an audio clip at specific position and modifies various audio settings such as random volume or pitch depending on the method called.

F3DBeam

This script is mainly used for updating beam weapons such as beam laser with uv animation for tiled textures, real time raycasting and interacting with rigid bodies by applying AddForceAtPosition. It is also scales the texture along its length depending on the beam length so it’s never gets stretched.

F3DDespawn

This script is used to despawn most of the effects after predefined delay by calling corresponding method of the pool manager that is included in this package.

F3DFlameThrower

This script is used by flame thrower prefab to manage some utility tasks such as fading in/out the lights and despawning the effect.

F3DFXController

This script defines all the weapon types and the way the are spawned such as managing prefab references, rate of fire, invoking specific audio routines and finally the GUI drawing seen in turret example.

F3DLightning

This script is mainly used for updating lightning gun weapon such as updating amount of lightning points and animating the uvs. It is also scales the texture along its length depending on the beam length so it’s never gets stretched.

F3DMissile

This script is a missile controler. It has several modes of operation such as: Unguided, Guided and Predictive. An assigned target is required for Guided and Predictive modes to operate. Only the Unguided mode uses ray casting to detect colliders and relies on RaycastAdvance variable. Guided and Predictive modes rely on the DetonationDistance variable. In Predictive mode make sure to set the missile velocity variable large enough to catch up with the moving target to avoid unnatural missile trajectories.

F3DPool

This script is a pool manager which is used to pre instantiate all the provided prefabs before the scene starts playing. All weapon scripts use OnSpawned and OnDespawned methods which also makes them compatible with other pool managers found on the asset store.

F3DProjectile

This script is a projectile controller. It is using ray casting to detect colliders in advance and in case of an impact calls corresponding method to play sound effects and spawn impact prefabs.

F3DPulsewave

This script is used to control pulse wave scaling and fading over time.

F3DRandomize

This script is used to randomize transform’s scale and rotation for currently spawned object. Mainly used with muzzle flashes and projectiles.

F3DShotgun

This script is used to manage shotgun particle system and react to particle collision events sent by spawning impact prefabs and playing audio clips at impact points.

F3DTime

F3DTime class is a singleton instance used to create and manage the timers. To start using this component simply attach it to any gameobject in scene use one of the following overloads to create a timer: int F3DTime.time.AddTimer(float rate, System.Action callBack); int F3DTime.time.AddTimer(float rate, int ticks, System.Action callBack); AddTimer method has two overloads. The first one can be used to invoke a specified method at specified rate until stopped while the second one requires you to specify number of ticks before it stops. The return value of AddTimer is a unique int handle which should be used with RemoveTimer method to stop it’s execution. Let’s look at the code example below where two timers are created. Note that we store the id for the first timer in myTimerId variable so we could dispose it later.

Once initialized the first timer will begin invoking OnTimer method each 0.1 seconds until stopped by second timer after 5 seconds elapses. Then both timers are disposed since we explicitly tell first timer to be removed and the second self removes since it’s life scope is only a single tick.

F3DTurret

This script is used to control turret’s base and barrel rotation in a specified range as well as checking user input and invoking weapon firing methods on F3DFXController.

F3DWarpJump

Controls the warp jump effect by sending the appropriate messages to child objects invoking mesh tunnel scaling. Moves the warp spark through the tunnel and updates ShipPosition gameobject. Make sure to disable SendOnSpawned before using with pool manager.

F3DWarpJumpTunnel

The script is responsible for scaling the warp jump tunnel mesh, fading colors, and rotation. Should be used with F3DWarpJump script. F3DWarpTunnel Randomly rotates the warp tunnel over time.