# Initial page


# Introduction

**DESIGN CONCEPT**

![](https://4289778471-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-MVKw8MgRKSYbFzCqlnm%2F-MW4gJgMgrILKkXZ-Y6-%2F-MW4l2XGwcyPJhRgJhu-%2FPromo%2002.PNG?alt=media\&token=7097e0f0-94ef-4283-94a4-9f0ab23e6225)

This tool's main goal is to create a versatile and modular system for building various traps and environmental hazards. By separating the trap control unit from the mechanisms, each part of a trap's movement and effects can be controlled and re-used. Each mechanism can have its own set of audio and particle effects and damage components.

For example, if you have a saw trap that rotates and slides up and down in its slot, it consists of two movements. Each movement can be controlled separately, without the need to edit a pre-made animation. If you want the slot to be longer, you only need to edit the modular slot parts and tweak the sliding mechanism a little.&#x20;

![](https://4289778471-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-MVKw8MgRKSYbFzCqlnm%2F-MW-OYLs8tDw5vE4AOiA%2F-MW-gWokUnDZTHjMvacj%2FTrap%20System%20Graph.jpg?alt=media\&token=f7acac6d-92c2-483f-b63a-c5d75bbd6345)

**Trigger:** This component interacts with the player, and controls the trap by activate, deactivate or toggle.

**Trap:** representation of the trap which contains the mechanisms. One trap can control multiple mechanisms.

**Mechanism:** These components define how the trap parts work. You can combine multiple mechanisms  for complex trap movements - for example, a rotating blade that also slides up and down in a slot.

**Effect Handlers:** Use the effect handlers to subscribe to certain mechanism events and play, pause and stop particles or audio clips.&#x20;

**ADDING TRAP COMPONENTS TO A GAME OBJECT**

You can access these tools from the component menu by either navigating to the desired component, or typing in the search bar and choose from the results.

<div align="center"><img src="https://4289778471-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-MVKw8MgRKSYbFzCqlnm%2F-MVKwCJ8jaI8aHdVIvh8%2F-MVKwo2DrMrn2bcH-MeW%2Fcomponent%20menu.jpg?alt=media&amp;token=5aaf9de9-fd1e-4f50-b482-a169e53d366e" alt=""></div>

#### QUICK ACCESS TO THE DOCUMENTATION

In the Inspector, clicking on the help icon ![](https://runemarkstudio.com/wp-content/uploads/2019/08/help.jpg) will open the corresponding page.


# Trap Triggers

![](https://4289778471-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-MVKw8MgRKSYbFzCqlnm%2F-MW4rkN5WrLNRM-9-4pg%2F-MW4utPVxt0oZTeRFX7r%2Ftrigger-illustration.PNG?alt=media\&token=6b0c8c9d-36b7-4c05-aef4-dc8e9ec2b301)

Use this component to create player interaction with the trap. You can create trigger zones that activate the trap when the player enters, such as a pressure plate. You can use this component in a more advanced way, like using a disarm box when the player presses the E key.

This component depends on a Collider, with the *isTrigger* parameter enabled.

![](https://4289778471-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-MVKw8MgRKSYbFzCqlnm%2F-MVvZYgHtDHOHnuPzvyi%2F-MVvgTfuHgA3WoZeOyd2%2Ftrigger.PNG?alt=media\&token=caf3627d-670a-430f-8b08-dcd0129329cf)

* **Trap:** drag and drop the trap that this trigger manipulates.
* **Action:** you can activate, deactivate the target trap, or toggle between these two states.
* **Cooldown:** how many seconds before the trigger would work again.
* **Tag:** only trigger when a game object with one of these tags enter. In most cases, this will be the Player.
* **Interaction:** You can allow the player to execute an action by pressing a button while staying in the trigger area instead of just walking into it. You can use [Key Codes](https://docs.unity3d.com/ScriptReference/KeyCode.html) or [Unity Input](https://docs.unity3d.com/Manual/class-InputManager.html).
* **Events:** You can use these events to make visual effects for the trigger or show/hide a UI element.

{% hint style="info" %}
You can use this component without a trap, but currently, only the **Activate** and the **Deactivate** actions are supported.
{% endhint %}


# Raycast Triggers

![](https://4289778471-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-MVKw8MgRKSYbFzCqlnm%2F-MW9P0V_gl1Gcgj_1iBd%2F-MW9SIioiRbFOet4ekI-%2Flaser-trigger.PNG?alt=media\&token=5e55bab2-d6f4-4181-9ac7-2bb47dbb4811)

Use this trigger type for detector rays. Note that this is a trigger behavior only, for visualizing the laser beam you need a Ray Handler too.&#x20;

* **Trap:** the trap this detector ray controls.&#x20;
* **Action:** Activate, Deactivate or Toggle. (For Toggle you always need to specify a trap)
* **Cooldown:** time (seconds) until the trigger can react to events again.
* **Max Distance:** how far the ray (laser) should extend.&#x20;
* **Layer Mask:** use these to include or exclude objects from raycasting.
* **Tag Filter:** the trigger reacts when the raycast hits a game object with these tags.
* **Events:** you can set Unity Functions on specific events, for example, play audio, particle effect, or animation.&#x20;


# Disabling Traps with Triggers

![](https://4289778471-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-MVKw8MgRKSYbFzCqlnm%2F-MW4rkN5WrLNRM-9-4pg%2F-MW5-th7sAi7T92_t9QQ%2Fdisable%20device.PNG?alt=media\&token=2e7668a3-3ce0-4971-9bd6-ace096316a3e)

To create a game object that can disable an already active trap, use a [Trigger](https://deadlydocs.runemarkstudio.com/traps/triggering-a-trap) to control player interactions.

* Assign the trap component.
* Set Action to Disable, and the cooldown greater than 0 (to avoid fast repetitive action).
* Set Tag filter to Player.
* Interaction to Key Code, usually E.&#x20;
* Set Events if you want to show or hide UI, spawn particles such as sparks or audio when the action happens.

![](https://4289778471-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-MVKw8MgRKSYbFzCqlnm%2F-MW50coGHKXPPodDgFHe%2F-MW50yyseN-k3XvekP-1%2Fdisable-example%2001.PNG?alt=media\&token=209ab43a-5564-4ca3-910f-75d0981e8582)

![In this example, the pressure plate activates the sawblade, and the touch panel disables it.](https://4289778471-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-MVKw8MgRKSYbFzCqlnm%2F-MW50coGHKXPPodDgFHe%2F-MW51vRLMT-EcCAHEQa2%2Fdisable%20example%2002.PNG?alt=media\&token=2d3185e7-a3d6-45d4-8775-8d1934fa9837)


# Trap

![](https://4289778471-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-MVKw8MgRKSYbFzCqlnm%2F-MW52twd1CBHJ1Wr-ffw%2F-MW52yrB3TICfe0xbU26%2Ftrap%20base.PNG?alt=media\&token=f98d4510-8fec-4be1-a0cd-8cde394fe1fe)

This component organizes the different [mechanisms](/traps/trap-mechanism) into a single trap and activates them when it is triggered.

![](https://4289778471-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-MVKw8MgRKSYbFzCqlnm%2F-MW-lhwhUt9zy4dIOM2X%2F-MW-m8FocT-hllABncHj%2Ftrap-screenshot.PNG?alt=media\&token=b374a76d-8163-443b-83fa-448afd93c259)

* **Start Mode:** Selecting the OnAwake option will automatically activate the trap when the game starts. OnEvent allows you to activate with a TrapTrigger or directly from a script.
* **Sync:** Uncheck this option to set an activation delay for each mechanism.
* **Mechanism:** You can add or remove as many mechanisms as needed.

You can access the following methods and parameters from the code.

```csharp
// Returns if the trap is currently active or not.
bool isActive { get; }    

// Activates the trap if Start Mode is set to OnEvent.
void Activate()     

// Inactivates the trap.
void Deactivate()

// Toggles between active and inactive states. 
// Can only activate if Start Mode is set to OnEvent.            
void Toggle()                
```


# Trap Mechanism

![This trap has two mechanisms: one for rotating the saw, the other for moving it along the slot.](https://4289778471-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-MVKw8MgRKSYbFzCqlnm%2F-MW53-WZTmJGsoTd3yjx%2F-MW54IrhTT5RZDmZwWX-%2Ftrap%20component%20illustration.PNG?alt=media\&token=0aed7334-a17a-4fc6-8f14-ac7c7d9fb89a)

These components define how the trap works: moving, rotating using physics or particles, and launching projectiles.

You can use multiple mechanisms in a single trap. Putting them together as parent-child will result in a more complex trap.&#x20;

![](https://4289778471-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-MVKw8MgRKSYbFzCqlnm%2F-MVKyiy9HbN9QgTAhEWo%2F-MVKyumnmTJzVNau29dD%2Fmechanics.jpg?alt=media\&token=7df2204d-b86a-4a16-802d-caf73d3c42f8)

* **Play Mode:** After activation, the mechanism executes itself once only, or as a loop until the deactivation happens.
* **Cooldown:** Seconds before the mechanism can reactivate.  0 means no cooldown.
* **Reset on Finish:** This only available in Only Once play mode.&#x20;
* **Effects:** A list of rules that controls effects. Assign an [**Effect Handler**](/traps/effect-handlers/custom-effect-handler) to call a selected command on it when an Event happens.
* **Command:** what should the effect handler do when the selected event happens.

{% content-ref url="/pages/-MVKyxvpXSAweFWXBLb5" %}
[Animator](/traps/trap-mechanism/trap-animator)
{% endcontent-ref %}

{% content-ref url="/pages/-MVKzToDoQzN63ojngVQ" %}
[Launcher](/traps/trap-mechanism/trap-launcher)
{% endcontent-ref %}

{% content-ref url="/pages/-MVKzt-8YYDl1dSFaJPN" %}
[Particle (Trap Mechanism)](/traps/trap-mechanism/particle)
{% endcontent-ref %}

{% content-ref url="/pages/-MVKzwglKVhlkqIKkBLW" %}
[Physics](/traps/trap-mechanism/physics)
{% endcontent-ref %}


# Animator

![](https://4289778471-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-MVKw8MgRKSYbFzCqlnm%2F-MW4rkN5WrLNRM-9-4pg%2F-MW4sDG68NAPX1JF97R5%2Fanimator-illustration.PNG?alt=media\&token=82c3493d-05fc-4c75-8713-3e48a87257f1)

This script gives us the option to use procedural animation instead of keyframe animations to control the traps. By changing the parameters, you can achieve many different results.

* **Play Mode:** the animation can happen only once, or continuously (Loop).&#x20;
* **Cooldown:** how many seconds before the animation starts over when set to Loop. 0 means instant.

### **Loop Settings**

This section only available if you selected the Loop play mode. You can control how to use a loop in this mechanism.

![](https://4289778471-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-MVKw8MgRKSYbFzCqlnm%2F-MW4aTxRe8M1EQLB7-gs%2F-MW4awudvTq0_F8yQl-Y%2Fanimator-loop.PNG?alt=media\&token=87476fae-e96d-4e59-8678-dda5dfd861b9)

* **Loop Mode:** *Repeat* is the standard loop mode. In the case of *Ping-Pong,* the loop goes back and forth.
* **Duration:** how many seconds to finish one loop.
* **Curve:** you can customize the movement dynamic with this curve.
* **Different Reverse (only in Ping Pong mode):** Enabling this option allows you to set different duration and curves when the loop goes backward.

### **Animator Settings**

* **Translate:** the script moves the game object between the start position and the end position. This movement is relative to the anchor transform (Local Space).&#x20;

![](https://4289778471-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-MVKw8MgRKSYbFzCqlnm%2F-MW4bB32nMlUbPym5-Nw%2F-MW4bUot4yM6M2xQUvYg%2Fanimator-translate.PNG?alt=media\&token=7b2af09c-830a-4c22-bf6f-fa140affd515)

* **Rotate:** the script rotates the game object by the given angle over the time of the duration, around the given axis, in local space.&#x20;

![](https://4289778471-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-MVKw8MgRKSYbFzCqlnm%2F-MW4bB32nMlUbPym5-Nw%2F-MW4csOvnjmyHWoXYYWH%2Fanimator-rotate.PNG?alt=media\&token=8fed4cd0-f566-464e-a37a-0d43e8849e7a)


# Launcher

![](https://4289778471-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-MVKw8MgRKSYbFzCqlnm%2F-MW4gJgMgrILKkXZ-Y6-%2F-MW4rdHq_TmAHFs_tddC%2Flauncher-illustration.PNG?alt=media\&token=6c18f9da-b871-4a33-919f-bd9916396dfe)

This component shoots a projectile using object pooling. In short, it only instantiates a number of projectiles then reuses the already instantiated. This is good for performance. ([more information here](https://learn.unity.com/tutorial/object-pooling)).

* **Play Mode:** the projectile is spawned and launched Only once or continuously (Loop).
* **Cooldown:** the time (in seconds) between two spawn events.

![](https://4289778471-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-MVKw8MgRKSYbFzCqlnm%2F-MW4bB32nMlUbPym5-Nw%2F-MW4d_7CCHIhMK6gRISg%2Flauncher.PNG?alt=media\&token=63a678c8-6391-43c1-aada-e70dc3c2ef56)

**Launcher Settings**

* **Force:** the force that is applied to the projectile
* **Max Distance:** projectile deactivates and returns to the pool after this distance even if it didn’t collide with anything.
* **Ammunition:** you can limit how many times the launcher can shoot. 0 means unlimited ammo.
* **Stick on Collision:** the projectile will stick to and move with the object it collides with. It disappears when the object pooler reuses it. Useful for arrows or darts.

**Projectile Settings**

* **Projectile:** The script can handle multiple **projectile prefabs**.  By default, it shoots the listed projectiles one by one, based on their order. Enable the Randomize option for random selection.
* **Pool Size:** the script will instantiate only this amount of projectile from each prefab.

### Trap Projectile

This component moves the projectile. It’s inherited from a [Damage Source](https://runemarkstudio.com/deadly-dungeon-traps/documentation/damage-system/), so you can set the damage.

![](https://4289778471-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-MVKw8MgRKSYbFzCqlnm%2F-MW4bB32nMlUbPym5-Nw%2F-MW4eTVR43KfB723zZRr%2Fprojectile.PNG?alt=media\&token=692d4cdf-a076-4ef2-a4a6-ac8f2076a89d)

To create a **projectile prefab** to be used in the launcher, simply attach this script to a game object and save as a prefab in your Project folder.

![](https://4289778471-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-MVKw8MgRKSYbFzCqlnm%2F-MW4bB32nMlUbPym5-Nw%2F-MW4fD6W5aL1IAE25_Wp%2Fprojectile-prefab.PNG?alt=media\&token=789d83e5-a71e-4432-b689-22a4d2658f01)


# Particle (Trap Mechanism)

![](https://4289778471-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-MVKw8MgRKSYbFzCqlnm%2F-MW4gJgMgrILKkXZ-Y6-%2F-MW4r6538tcljSzZD_hj%2Fparticle-illustration.PNG?alt=media\&token=11fc0538-9caa-4762-8978-5695e10066ca)

This mechanism controls a Particle System as a trap mechanism and its associated Particle effects and Audio components.

![](https://4289778471-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-MVKw8MgRKSYbFzCqlnm%2F-MW-nYP36-PeM8oBbLhI%2F-MW-oIoSXrek3t8pZ1TN%2Fparticle-screenshot.PNG?alt=media\&token=0504a281-df47-4d4a-a43a-211c72a7eacf)

**Particle:** Assign a Particle System you wish to control from here.

**Play Mode:** how long the particle is played when the mechanism is triggered. Loop or Only Once.

**Cooldown:** how long (in seconds) before the trap can be triggered again.

**Effects:** you can add or remove [*Audio handlers*](https://app.gitbook.com/@runemarkstudio/s/deadly-dungeons/~/drafts/-MVv5Wz9S1GutR_VLVPo/traps/effect-handlers/audio-handler) or [*Particle effect handlers* ](https://app.gitbook.com/@runemarkstudio/s/deadly-dungeons/~/drafts/-MVv5Wz9S1GutR_VLVPo/traps/effect-handlers/particle-handler)here and control their behavior on specific events such as Loop start, Loop end, Activate or Deactivate. \
Commands include Play Once, Play, Stop and Pause.&#x20;


# Physics

![](https://4289778471-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-MVKw8MgRKSYbFzCqlnm%2F-MW54q5J8Sj5vQgXVh3W%2F-MW55YGHA2GQjeR3ELoN%2Fphysics%20trap%20illustration.PNG?alt=media\&token=236ef129-b4a1-4c31-8894-97899868085d)

This simple mechanism controls the [Rigidbody](https://docs.unity3d.com/Manual/class-Rigidbody.html) on the same GameObject. On activate, the script turns off the *isKinematic* property and allows the physics engine to apply gravity to this object.

![](https://4289778471-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-MVKw8MgRKSYbFzCqlnm%2F-MVv4Yx2p0KBh5nP4n8z%2F-MVvDYzQyK3OZ_J75LzF%2Fphysics.PNG?alt=media\&token=73c9fa47-f15c-437d-b63c-8470bc257e53)

* **Play Mode:** determines if the trap should activate once, or loop.&#x20;
* **Cooldown:** how long (in seconds) before the trap can be activated again.
* **Reset on Finish:** This only available in Only Once play mode. After the simulation ended, the script resets the game object position and rotation. In loop mode, this is automatically happening after every sequence.
* **Duration:** how long the physics simulation should happen.&#x20;
* **Effects:** Add or remove [Particle effects handlers](https://app.gitbook.com/@runemarkstudio/s/deadly-dungeons/~/drafts/-MVv5Wz9S1GutR_VLVPo/traps/effect-handlers/particle-handler) and [Audio handler](https://app.gitbook.com/@runemarkstudio/s/deadly-dungeons/~/drafts/-MVv5Wz9S1GutR_VLVPo/traps/effect-handlers/audio-handler) here, and control their behavior based on the events.


# Effect Handlers

These components control different visual or audio effects. You can add them to the list on the [Trap Mechanism](https://runemarkstudio.com/deadly-dungeon-traps/documentation/trap-mechanism/) components.

* **Delay:** how many seconds after the command executes after triggering.

Methods you can call with the commands in the mechanism or directly from code. Not all of these are available for every handler type.

```csharp
// Only plays the effect once.
void PlayOnce() 

// Start playing the effect indefinitely
void Play()      

// Paused the effect. When the play called, it resumes.
void Pause()     

// Stops the effect and resets it
void Stop()    
```

{% content-ref url="/pages/-MVL-ZrM5pqS2Nw2B487" %}
[Audio Handler](/traps/effect-handlers/audio-handler)
{% endcontent-ref %}

{% content-ref url="/pages/-MVL-cutAZ3LAdJ3O3oL" %}
[Particle (Effect Handler)](/traps/effect-handlers/particle-handler)
{% endcontent-ref %}

{% content-ref url="/pages/-MVL-ifQYPvg7yTVPrSN" %}
[Custom Effect Handler](/traps/effect-handlers/custom-effect-handler)
{% endcontent-ref %}


# Audio Handler

![](https://4289778471-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-MVKw8MgRKSYbFzCqlnm%2F-MW55k5iUjQbeBuIwxVh%2F-MW56v0oGKkWAzifrEmH%2Faudio%20illustration.PNG?alt=media\&token=098e028a-9854-4523-b623-59dde75f068c)

&#x20;This component controls the [Audio Source](https://docs.unity3d.com/ScriptReference/AudioSource.html) on the same object. As a parameter, it requires an audio clip. All the commands (Play Once, Play, Stop, Pause) are available.

![](https://4289778471-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-MVKw8MgRKSYbFzCqlnm%2F-MVv4Yx2p0KBh5nP4n8z%2F-MVvFaxnmd4cJHWxIrzu%2Faudio%20handler.PNG?alt=media\&token=45322a2c-2820-4af8-957a-148797cb03be)


# Particle (Effect Handler)

![The sparks on this saw are controlled by the Particle Handler.](https://4289778471-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-MVKw8MgRKSYbFzCqlnm%2F-MW55k5iUjQbeBuIwxVh%2F-MW58PR1_yIH4HSxCuwk%2Fparticle%20illustration.png?alt=media\&token=b377bd6c-e532-4f24-a9f8-7cd0ab879a62)

This component has two modes.&#x20;

* **Normal:** controls the assigned particle system. (Play Once command not available!)
* **Instantiate:** spawns a particle instance from the prefab.
* **Delay:** how long (in seconds) before the particle starts playing after it has been triggered.

![](https://4289778471-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-MVKw8MgRKSYbFzCqlnm%2F-MVv4Yx2p0KBh5nP4n8z%2F-MVvGZlnbOAcsCr-pHOu%2Fparticle%20handler.PNG?alt=media\&token=f08aea49-18bc-4088-a4f2-f91910eab18b)


# Ray Handler

![This laser beam is controlled by a Ray handler script](https://4289778471-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-MVKw8MgRKSYbFzCqlnm%2F-MW59D3qOHVhA2iPKw1D%2F-MW597xcBaaBpt__ncaf%2Fray%20illustration.PNG?alt=media\&token=a7ecf2fb-8a8f-45d2-8d58-9493ada84d8b)

This component controls a [Line renderer](https://docs.unity3d.com/Manual/class-LineRenderer.html) to work as a laser. It uses a [Physics Raycaster](https://docs.unity3d.com/Packages/com.unity.ugui@1.0/manual/script-PhysicsRaycaster.html) to determine if the laser hits something. Resizes the line renderer to match the raycast result.

Note: Rays can be only controlled by a Ray Handler.

* **Play On Awake:** activates the effect on awake.
* **Delay:** how long (in seconds) before the laser becomes visible after activation.
* **Line Renderer:** Line renderer that represents the laser.
* **Spark Particle:** A particle that appears at the end of the laser where it hits something.
* **Max Distance:** How far can the laser extends.
* **Obstacle Layer Mask:** You can ignore certain layers that do not interrupt the laser beam.

![](https://4289778471-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-MVKw8MgRKSYbFzCqlnm%2F-MVv4Yx2p0KBh5nP4n8z%2F-MVvGvfp9-Z0DyNfOKsb%2Fray%20handler.PNG?alt=media\&token=b1721242-ec7e-4e0d-8e18-76eef48e6a64)


# Custom Effect Handler

Our approach with this component is to extend the usability of the asset. If none of the above effect handlers suits your needs, and you don’t want to or can’t code your own one, this script could be a great help.

You can add or remove Unity methods to each effect event.

![](https://4289778471-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-MVKw8MgRKSYbFzCqlnm%2F-MVv4Yx2p0KBh5nP4n8z%2F-MVvJA8Rn9uEOY-HPU-T%2Fcustom%20handler.PNG?alt=media\&token=cd10b683-f2ef-47a8-8ba6-45fe9168999e)


# Damage System

The asset comes with a damage system that is easy to extend and integrate into your project.&#x20;

{% hint style="warning" %}
This chapter requires intermediate Unity and basic programming knowledge.
{% endhint %}

{% content-ref url="/pages/-MVL-tokId-qdI1uScyd" %}
[Damage Source](/traps/damage-system/damage-source)
{% endcontent-ref %}

{% content-ref url="/pages/-MVL01TYKT\_q69smWQj0" %}
[Damage Result](/traps/damage-system/damage-result)
{% endcontent-ref %}

{% content-ref url="/pages/-MVL0AQ4K8a6Db\_wW6aR" %}
[IDamageable](/traps/damage-system/idamageable)
{% endcontent-ref %}


# Damage Source

This component does the specified Damage to all *IDamageable* that qualifies for its condition. These are based on the mode and the duration of the damage source.&#x20;

**Modes:**

* **Volume:** Does damage amount as long as the damageable is within the volume. Needs a Collider set to Trigger.

![](https://4289778471-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-MVKw8MgRKSYbFzCqlnm%2F-MVv4Yx2p0KBh5nP4n8z%2F-MVvKMytzddv3Ek67eeF%2Fdmg-volume.PNG?alt=media\&token=32182a47-aca7-445a-a13e-0f15ca9a39ac)

* **Contact:** Needs a Collider (leave *isTrigger* unchecked). Important: don't forget to set your collision Layers accordingly.&#x20;

![](https://4289778471-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-MVKw8MgRKSYbFzCqlnm%2F-MVv4Yx2p0KBh5nP4n8z%2F-MVvJrzg0K-AbeRhqG6u%2Fdmg-source01.PNG?alt=media\&token=91d0b6b9-d991-4e07-a6f7-edd0933b8a2b)

* **Particle:** Needs a Particle Handler and a Particle System with Collisions turned on. The component deals the specified damage when the target is colliding with the particles.
* Tick Cooldown: specifies the time between two damage events. This is useful for dense particle systems where you don't want the player to suffer damage from each particle he collides with.

{% hint style="info" %}
Important: Particle Mode only works with Continuous duration.&#x20;
{% endhint %}

![](https://4289778471-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-MVKw8MgRKSYbFzCqlnm%2F-MVvZYgHtDHOHnuPzvyi%2F-MVvbTtkEcF4OQblHimc%2Fdmg-particle.PNG?alt=media\&token=df771b5b-0564-4c6b-92ce-c4c143a33f55)

* **Ray:** Needs a [Ray Handler](https://app.gitbook.com/@runemarkstudio/s/deadly-dungeons/~/drafts/-MVv5Wz9S1GutR_VLVPo/traps/effect-handlers/ray-handler). This component deals damage when the Raycast from the handler hits its target, specified by Layer Mask. Can be used with all duration modes.

![](https://4289778471-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-MVKw8MgRKSYbFzCqlnm%2F-MVv4Yx2p0KBh5nP4n8z%2F-MVvOVE-_F7oPOuVeZ5B%2Fray-dmg.PNG?alt=media\&token=cb756bc5-11b0-4a17-b407-90215c368b9d)

**Duration:**

* **Once:** the damage event is happening once per event.
* **Continuous:** the damage is dealt until the collision is happening (for example, the player is within the damage volume, or in contact with the trap's collider.)
* **Tick Cooldown** is the time (in seconds) between two damage events.&#x20;
* **Controlled by Mechanism:** the trap will only deal damage on certain Mechanism Events. Drag this component to an empty Event slot and specify an Action. &#x20;


# IDamageable

The damage source will use this interface to do damage. Here is a simple implementation of this interface.​

```csharp
public class ExampleDamageable : MonoBehaviour, IDamageable
{
    public int Health = 100;

    public void TakeDamage(DamageResult result)
    {
        Health -= result.damage;
        if (Health <= 0)
        {       
            // Do something on death
        }
    }
}
```


# Damage Result

As a default, this class contains only a single damage parameter. You can easily extend it to support your idea better.

When the damage happens, a Damage Source will forward this result to the IDamageable where you can take care of every parameter in the result object.

![](https://4289778471-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-MVKw8MgRKSYbFzCqlnm%2F-MVL-EAgje8m1eYJT8u7%2F-MVL04RjW-0xpBy7cybO%2Fdmgresultbase.jpg?alt=media\&token=fd2b5e37-19d3-43f8-947f-c8ffe691e968)


# Damageable Example

![](https://4289778471-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-MVKw8MgRKSYbFzCqlnm%2F-MW59uBQG55DkPQumPH3%2F-MW5AoYAeechdqunDmZP%2Fdamageable%20example.PNG?alt=media\&token=1b32da1a-c710-4b97-b254-5e85324b5250)

The Damageable example is handling the visual and audio representations of the damages done to the player. You can determine the Max HP, and assign various functions.


# Utility


# AutoConnect Joint

This script is useful when you have a skinned mesh with lots of bones that are parented to each other as a chain. Useful for long ropes and cables which use Physics simulation.

**Quickly Connecting Character Joints**

![](https://4289778471-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-MVKw8MgRKSYbFzCqlnm%2F-MW9Wzcj-cpuGOKGzzll%2F-MW9_mPXaE-y2o-f3qTm%2Fconnectjoint02.png?alt=media\&token=91c38f77-8037-47b9-98b1-95618ffc0d6f)

First, add a *Character Joint* and a *Rigidbody* to all the bones of the rope armature. You can select all the bones in the Hierarchy and add the components to all of them at once. The script will take care of the connected bodies.&#x20;

![](https://4289778471-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-MVKw8MgRKSYbFzCqlnm%2F-MW9iU3F5_0YQL16Be8w%2F-MW9jlJmMK0NilqfFoH4%2Fconnect%20joint.PNG?alt=media\&token=c72b41ec-9e8f-47e0-bf44-28c4bb9ab1d1)

Attach the script to the last bone, then click on the component menu, and choose Connect Joints Upward.

![](https://4289778471-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-MVKw8MgRKSYbFzCqlnm%2F-MW9Wzcj-cpuGOKGzzll%2F-MW9_jH6XTV3aE1CwUtR%2Fconnectjoint.PNG?alt=media\&token=fc6f1b7d-cb83-436c-9e1c-4261ee956f7e)

The bones are now connected, and you no longer need this component. You can tweak the joint parameters, rigid bodies and colliders all at once.&#x20;

![The swinging trap uses character joints and physics simulation for the cable.](https://4289778471-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-MVKw8MgRKSYbFzCqlnm%2F-MW9Wzcj-cpuGOKGzzll%2F-MW9cHyTloC8zUmBjEa1%2Fphysics%2001.PNG?alt=media\&token=69a61b6d-f06e-4585-a695-d1b285236882)


# Texture Mover

You can define states in this component and assign texture offsets to this state.&#x20;

The script iterates through all the children's renderers and sets the main texture offset to the value defined in the given state.

```csharp
public void SetState(string name)

// Resets the state to the first one in the list.
public void ResetState()
```

**Setting up the Texture Mover**

Attach the script on the game object you want to modify. Add States and fill out the corresponding UV Coordinates for each state.

![](https://4289778471-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-MVKw8MgRKSYbFzCqlnm%2F-MW9Wzcj-cpuGOKGzzll%2F-MW9fg4bAMACD2GSllYw%2Ftexture%20mover%2001.PNG?alt=media\&token=fc35447d-95d9-40d0-bbab-caeff4881160)

![](https://4289778471-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-MVKw8MgRKSYbFzCqlnm%2F-MW9Wzcj-cpuGOKGzzll%2F-MW9goPkOE7zbxptVwDU%2Ftexture%20mover%20example.png?alt=media\&token=5195ed21-16cf-4ebe-b739-64d4d609759c)

**Triggering the Texture mover**

You can raise this event from any Trigger as a Function.

![](https://4289778471-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-MVKw8MgRKSYbFzCqlnm%2F-MW9Wzcj-cpuGOKGzzll%2F-MW9hLVQk8qk5vfB4gwv%2Ftexture%20mover%20set%20state.PNG?alt=media\&token=6c47d0dc-c9fa-4bcf-8265-20da4d0acb42)

{% hint style="info" %}
**Note:** The script iterates on the game object and all its children and modifies the first Material instance it finds. It does not modify the Material in the project, only the instance it is attached. If a game object has multiple material slots, the script only modifies the first one.
{% endhint %}


