Hello all!
I’m very new to coding so please bear with me. My game features a ton of different enemies. Upon colliding with the player, each enemy runs a different function, causing UI elements to change depending on what enemy was collided with.
I am brainstorming what would be the best way to allow my game to recognize which enemy collided with the player and run the corresponding behaviour for that specific enemy.
I guess the easiest way would be to just slam 30 different if statements searching for each enemy tag into a void update() but that’s obviously awful practice as I’d be running so many different checks every frame.
Then I perhaps thought I could just stick those 30 if statements into their own void enemies() function and only call the function when the player bumps into an enemy. This sounds better since it’s not every frame but at the end of the day, I’ll still be running up to 30 different if statements every time I bump into an enemy.
Then I figured, what if I set up a separate function for each enemy that is identical to its tag (i.e. enemy with tag “orc” would get a void orc() function in the Game Manager. Then, I set up my Game Manager to grab the tag of the collided enemy as a string whenever the player collides with an enemy and run void “string”(). This way, I wouldn’t even have to run through all the 30 if statements and I could just skip right to the appropriate function for each enemy.
Would this be possible? Or am I way off base here? Is there a better upgrade I could make to organizing a system for recognizing what enemy my player bumps into and running the appropriate behaviour for each unique enemy upon collision?
Thank you for your time!