# 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&#x20;

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&#x20;

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.&#x20;

### F3DBeam&#x20;

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.&#x20;

### F3DDespawn

&#x20;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.&#x20;

### F3DFlameThrower&#x20;

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&#x20;

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.&#x20;

### F3DLightning

&#x20;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.&#x20;

### F3DMissile

&#x20;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.&#x20;

### F3DPool&#x20;

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.&#x20;

### F3DProjectile&#x20;

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.&#x20;

### F3DPulsewave&#x20;

This script is used to control pulse wave scaling and fading over time.&#x20;

### F3DRandomize&#x20;

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

### F3DShotgun&#x20;

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&#x20;

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.

![](/files/-MAkr-2R6BHJIJXj0XU_)

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.&#x20;

### 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.&#x20;

### F3DWarpJump&#x20;

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.&#x20;

### F3DWarpJumpTunnel&#x20;

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.


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://docs.forge3d.com/sci-fi-effects/scripts.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
