Is it possible to call OnTrigerCollider2D() without binding any script to the Collider2D directly?

I want to use a single script to control all elements of one scene. Let’s call it “Director” script, bound to EventSystem.

I knew that I can get a GameObject by name or tag, and then manipulated the components such as transform. Thus I wondered if I can define the OnTrigerCollider2D() in this "Director” script without binding any script to the Collider2D GameObject, just like I define the value of the transform? If possible, how?

According to some friend, it is necessary to bind at least a basic script to the Collider2D to authorize the “Director” script to get access to the Collider2D event, no way to bypass this limitation?

hi;
I like that :slight_smile:
I also always want to do every thing on 1 script ;
thats some kind of give me better control over every thing;

u cant call onTrigger enter without attaching it a script but there are other ways;

as i saw before in a unity tutorial what u can do is
“Physics.SphereCast”

it creates a sphere around that object that u want but u can do this in your “Director” Script too;

u can have a list of objects and send the order to do the cast then return if they have imapt with another object or not;

i think but im not sure that “Physics.SphereCast” is a little heavy so what u need to do is create a time counter in your update method and do this cast after some frames passed like this :

void Update()
{
float TimeNeedToCast = 1;
float CurrentTimePassed;

if ( TimeNeedToCas < CurrentTimePassed)
{
// do all of your objects casting here
CurrentTimePassed = 0;
}
else
{
CurrentTimePassed += Time.detlaTime
}

}

so this will cast only after 1 sec ( not each fram ) so u are not worry about the heavy problem any more :slight_smile: