# Interactible Marker

Working File:

<figure><img src="https://2410317992-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FuIWMObJSZIkZU4o3Yuje%2Fuploads%2Fe0dqmjzxccsSk8gajKD3%2Finteract.png?alt=media&#x26;token=8e3a8264-43b0-4910-8deb-7121612f9625" alt=""><figcaption></figcaption></figure>

## Setup

Change the color of the static sprite to have 0 Alpha. Remove the Rigidbody2D and click on "Is Trigger." Edit the collider so that it accurately tells the range.

<figure><img src="https://2410317992-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FuIWMObJSZIkZU4o3Yuje%2Fuploads%2FMTX3er6K0zwA3IY3CukC%2FInt01.png?alt=media&#x26;token=55d8af89-2e25-43e7-ba26-83607a256dbe" alt=""><figcaption></figcaption></figure>

<figure><img src="https://2410317992-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FuIWMObJSZIkZU4o3Yuje%2Fuploads%2FuSNRpLJgTg2gc08i7RlD%2FInt02.png?alt=media&#x26;token=08941ecf-8e44-424e-ad39-30173b93961a" alt=""><figcaption></figcaption></figure>

<figure><img src="https://2410317992-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FuIWMObJSZIkZU4o3Yuje%2Fuploads%2F6cv5Ma6HnbjyF7AuJJ48%2FInt03.png?alt=media&#x26;token=80e4dc5d-2eda-470d-be22-3aed04d7fa43" alt=""><figcaption></figcaption></figure>

Now, just drag that UI sprite for the marker to the location you want it in the scene.

<figure><img src="https://2410317992-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FuIWMObJSZIkZU4o3Yuje%2Fuploads%2FHXE2Vbb3nFJcS9N1u0lC%2FMarker01.png?alt=media&#x26;token=a60de104-45a3-481e-867d-23a837a9c18a" alt=""><figcaption></figcaption></figure>

Then, make that marker sprite a child of the Interactible object.

<figure><img src="https://2410317992-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FuIWMObJSZIkZU4o3Yuje%2Fuploads%2FiA6TtjN5dWHOWq9cr5wG%2FMarker01b.png?alt=media&#x26;token=824464bb-8eef-46cd-9ea6-3d06915e1ba5" alt=""><figcaption></figcaption></figure>

## Coding the Script

This is going to be very simple. We will simply enable the marker when the player enters the trigger zone. You want to attach this below script to the Interactible gameObject in the scene.&#x20;

```csharp
using UnityEngine;

public class InteractibleMarker : MonoBehaviour
{

    [SerializeField] private GameObject marker;

    private void Start()
    {
        marker.SetActive(false);
    }

    //Upon collision with another GameObject
    private void OnTriggerEnter2D(Collider2D other)
    {
        if (other.gameObject.CompareTag("Player"))
        {
            marker.SetActive(true);
        }
    }

    private void OnTriggerExit2D(Collider2D other)
    {
        if (other.gameObject.CompareTag("Player"))
        {
            marker.SetActive(false);
        }
    }

}
```

Then, from the inspector, pull the marker sprite into the script component.

## Animation

Depending on the style, you may want the marker to move. With the marker sprite selected in the scene hierarchy, create a new animation. Go to the time you want the thing to change, and add transform property. Create a new keyframe with the changed values. If needed, use the dopesheet to make sure it is undulating correctly.

## Make a Prefab

Now, we can simply drag this as a child of the gameObjects and have it do all the same stuff all over again.

To make a prefab, pull that newly created gameObject in the scene view and pull it into the projects window of the folder of your choosing. I created a "Prefabs" folder.

<figure><img src="https://2410317992-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FuIWMObJSZIkZU4o3Yuje%2Fuploads%2FF2JXTtlXhwcNTNZR7nrb%2FDrag%20to%20Prefab.png?alt=media&#x26;token=b8199b92-3aed-4102-93b5-b6bb9162fc7a" alt=""><figcaption></figcaption></figure>


---

# 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://roxioxx.gitbook.io/unity-cookbook/ui-onlyfans/interactible-game-objects/interactible-marker.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.
