List the name of current colliders

All, I have an object sweeping across the screen from left to right. There are a series of objects to the right of this whose position can vary - each of these objects as a collider component.

I want to have text that appears on screen which returns the name of all of the colliders the sweeping object is currently passing through.

Is this possible? Is anyone able to provide some guidance?

Regards,

Something like this might be what you are looking for. Granted it is in “javascript” but I’m happy to help you translate anything.

Its amazing that everything I am looking for is always in Java. :frowning:

It would look something like…

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

public class MyTriggerObject : MonoBehaviour
{
   
    List<Collider> triggerList = new List<Collider>();

    void OnTriggerEnter(Collider other){
        if(!triggerList.Contains(other)){
            triggerList.Add(other);   
        }
    }

    void OnTriggerExit(Collider other){
        if(triggerList.Contains(other)){
            triggerList.Remove(other);   
        }
    }
   
    List<string> getColliderNames(){
        List<string> colliderNames = new List<string>();
        foreach(Collider col in triggerList){
            colliderNames.Add(col.gameObject.name);   
        }
        return colliderNames;
    }
}
1 Like

Many thanks for this, I will try it out.

Regards