SOLVED: Example of fully functioning scripts.
I’m a programmer who codes in a way that is heavily reliant on Public Variables in the inspector in order to connect different things together, and a big reason I have for doing this is so that I can make my Scripts easily modular.
I’m trying to figure out a way to effectively create working functions that act as OnTriggerEnter, Exit, and Stay but for a specific collider that I can find and connect to the script.
A theory I have for how to pull this off was to Make all the Colliders separate game objects, and to put a secondary script on those. This script would check for OnTriggerEnter, Exit and Leave as any normal script, but when it did, it would be called upon by the main Script to activate a specific function that is given the necessary data from the Trigger collision.
But I don’t want the secondary script to necessarily call on the Primary script’s function through connecting to it by its own public Scriptclass,(That would mean I’d have to make all of the in-Editor connections in the trigger object, as well as making several more of them. A massive detour for my Modular method of work.)
I want it to be the other way around that way I can just write the function as necessary, make a public gameObject/Scriptclass for the function to be activated by, plug it into the script, and it will work.
So the best way I can explain it, is that I need a reverse of SendMessage that only runs when it retrieves a message from another script, which script it retrieves the message from being a public gameObject/Scriptclass that can be edited in the editor.
There’s another concept I’ve seen to do something similar to this, but it has the problem of forcing you to put all the colliders on the same game Object and is kinda broken in the first place. I’d much prefer the first idea.
The reason it’s broken is that I found out that it comes with a delay because the OnTriggerEnter on the second script always runs after the OnTriggerEnter from the first script has finished, thus storing the variable, but not giving it to the first script until you repeat the process.
In order to fix this, I’d need a way To Force the Second Script’s OnTriggerEnter function to Run Before going to the next line of code in the OnTriggerEnter in the first one’s. is there way to do this?