In Cleaning Spree!, you play as a space janitor who has to perform cleaning tasks within a time limit. These tasks include mopping up goo puddles, herding escaped Grubs into their pens, and the subject for this snippet being throwing trashbags into a dumpster.
The design for the action is that through procedural generation, there would N amount of trashbags in a room with a dumpster and the player will have to walk up to a trash bag, pick it up, and toss it across the room into a dumpster. Upon each trashbag going into the dumpster, the task is done. For this action, it was decided that the Grab Action and Toss Action would be the same input key/button.
This was a Unity C# script that was made early on into the project, so it is still rough and being touched up to this day. but this script is an important one as it is one that shows evolution.
This script started off being a simple collide, input, pickup, and toss in conception, but from this, the script had to handle several edge cases found in testing as well as work with audio and AI systems which were created by other programmers.
A prime example of the evolving to handle edge cases is the section of the code that checks all nearby trash bags and chooses the closest. Before this was implemented, the player picking up a trash bag next to others had undefined behavior that often resulted in game breaking bugs. The change of putting any nearby trashbags (those that entered within a trigger collider of a player) into a list and only picking the closest one is how I fixed that problem.