This is something that I have wanted to try for a while, since I think that a lot of the games I’ve played over the year are based on similar logic - whether it be for the triggering of traps, cutscenes or the other.
Rather than a strictly time-based dropper like has been implemented in the videos I took the change to try making a script that would detect whether the player passes through a boundary before telling the dropper to drop between a lower and upper length of random time.
To do this I added a new empty gameobject beneath my dropper gameobject (named “Stamp”) with a box collider an a sensor script:
By adding a serialized field for the “Sensor” script I was able to pull when the sensors for the droppers were triggered and send them a coroutine with a ranged random length of time to drop towards the player:
A couple things could probably be improved in terms of creating an inspector input for varying the size of the trigger collider, and I’m not sure about there maybe being a better way of getting the “sensorTriggered” variable from a script on another object (maybe I could have just added a separate box collider trigger on the dropper gameobject - but then how would I differentiate two box colliders in script). (Seems like I’m probably wasting processing power by having code being triggered over and over again in update.)
P.S. I think it should have been mentioned that (at least on visual studio) the autocomplete can take care of renaming all occurrences of your variables if you right click on a variable name that you have changed.