[HELP] List instance not being destroyed OnTriggerExit

I have tried many other solutions but yet not success, I’m quite a beginner and wondering If I could receive some help :slight_smile:

 using System.Collections;
using System.Collections.Generic;
using UnityEngine;


public class LinkTest
{
    public GameObject link;
    public Connector connector;
    public string targetName;
}

public class Detector : MonoBehaviour
{
    public GameObject linkPrefab;

    private List<LinkTest> linksList = new List<LinkTest>();

    void OnTriggerEnter(Collider co)
    {
        if (co.gameObject.tag == "Enemy")
        {
            if (linkPrefab != null)
            {
                LinkTest newLink = new LinkTest() { link = Instantiate(linkPrefab) as GameObject };
                newLink.connector = newLink.link.GetComponent<Connector>();
                newLink.targetName = co.name;
                linksList.Add(newLink);

                if (newLink.connector != null)
                    newLink.connector.MakeConnection(transform.position, co.transform.position);
            }
        }
    }

    void OnTriggerStay(Collider co)
    {
        if (linksList.Count > 0)
        {
            for (int i = 0; i < linksList.Count; i++)
            {
                if (co.name == linksList*.targetName)
                    linksList*.connector.MakeConnection(transform.position, co.transform.position);
                // Everytime an enemy is outside the trigger deletes and remove the line renderer
            }
        }
    }

    void OnTriggerExit(Collider co)
    {
        if (linksList.Count > 0)
        {
            for (int i = 0; i < linksList.Count; i++)
            {
                if (co.name == linksList*.targetName)
                    Destroy(linksList*.link);
            }
        }
    }
}

There is no errors or warning so I’m quite confused why it isn’t working…

Try something like this:

    void OnTriggerExit(Collider collider)
    {
        if (linksList.Count > 0)
        {
            for (int i = 0; i < linksList.Count; i++)
            {
                if (collider.name == linksList*.targetName)*

{
Destroy(collider.gameObject);
}
}
}
}

@unity_BUJQdslYm7EuFQ Weirdly enough it still isn’t working.