> For the complete documentation index, see [llms.txt](https://saitama-studio.gitbook.io/essential-systems/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://saitama-studio.gitbook.io/essential-systems/systems/proximity.md).

# Proximity

A proximity system adds dynamic interactions by triggering events based on nearby objects, making the game world feel more responsive.

<figure><img src="https://3846168334-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FhjeEdzvIH0d5vrHiguxu%2Fuploads%2FNBfLKivDIfqTDz5IHfxs%2FScreenshot%202025-01-30%20150637.png?alt=media&amp;token=61e6f3b0-9ac9-4be6-a1c7-036a26766eb9" alt=""><figcaption></figcaption></figure>

The Proximity System is divided in two parts:

1. `Proximity Trigger` - triggers a proximity whenever it gets close to **any** `AProximity`.
2. `AProximity` - an abstract class that is easy to extend and gets triggered whenever the `Proximity Trigger` is getting close or leaves the proximity area.

The `Proximity Trigger` can be attached to any game object. For example; we can attach it to the player instance.

The `AProximity` cannot be directly used due to it being an abstract class. However, you can and should create a new script and extend the `AProximity` class. Here you can define whatever proximity behaviour you want. Let's take an example where a sphere changes its color:

```csharp
public class ChangeColorProximity : AProximity
{
    public Material inProximity, outOfProximity; // define some references to materials
    public MeshRenderer meshRenderer; // the renderer of the sphere
    
    // MUST be overriden. It tells us whenever a Proximity Trigger is close enough.
    public override void Entered()
    {
        meshRenderer.material = inProximity; // set the material.
    }
    
    // MUST be overriden. It tells us whenever a Proximity Trigger leaves the area.
    public override void Left()
    {
        meshRenderer.material = outOfProximity; // set the material.
    }
}
```
