# ForceProximityExit & Enter

{% stepper %}
{% step %}

### Create a script

```csharp
using UnityEngine;
using MeshAnimation;

/// <summary>
/// Example: drive MeshAnimationInteract.ForceProximityEnter/Exit
/// based on whether any tracked object enters the proximity radius.
/// Attach to the same GameObject as MeshAnimationInteract.
/// </summary>
public class MeshAnimationInteractExample : MonoBehaviour
{
    [Tooltip("Target with MeshAnimationInteract component.")]
    public MeshAnimationInteract target;

    [Header("Proximity")]
    [Tooltip("Objects to watch. Any one of them entering the radius triggers Enter.")]
    public Transform[] trackedObjects;

    [Tooltip("Enter radius (units).")]
    public float enterDistance = 3f;

    [Tooltip("Exit radius. Should be >= enterDistance to avoid flickering.")]
    public float exitDistance = 4f;

    private bool _isInRange;

    private void Update()
    {
        if (target == null) return;

        bool anyInRange = IsAnyTrackedInRange(_isInRange ? exitDistance : enterDistance);

        if (!_isInRange && anyInRange)
        {
            _isInRange = true;
            target.ForceProximityEnter();
        }
        else if (_isInRange && !anyInRange)
        {
            _isInRange = false;
            target.ForceProximityExit();
        }
    }

    private bool IsAnyTrackedInRange(float radius)
    {
        foreach (Transform t in trackedObjects)
        {
            if (t == null) continue;
            if (Vector3.Distance(target.transform.position, t.position) <= radius)
                return true;
        }
        return false;
    }

    private void OnDrawGizmosSelected()
    {
        if (target == null) return;
        Vector3 center = target.transform.position;

        Gizmos.color = new Color(1f, 0.8f, 0.1f, 0.3f);
        Gizmos.DrawWireSphere(center, exitDistance);

        Gizmos.color = new Color(0.4f, 0.92f, 0.55f, 0.5f);
        Gizmos.DrawWireSphere(center, enterDistance);
    }
}

```

{% endstep %}

{% step %}

### Add a target and a Mesh Animation Interaction

<figure><img src="/files/ufxChTpn1wrJbS5Cy7pe" alt=""><figcaption></figcaption></figure>
{% endstep %}

{% step %}

### Select the animations you want

<figure><img src="/files/6WLi3JUuPmBzNzVBhEeU" alt=""><figcaption></figcaption></figure>
{% endstep %}

{% step %}

### Done

A simple script is ready!
{% endstep %}
{% endstepper %}


---

# 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://tkkoi-developer.gitbook.io/tkkoiassets/mesh-animation/start/interaction/api/forceproximityexit-and-enter.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.
