Hello everyone, I need some information about function parameters in C#. Here is my situation: I have a singleton script called SubtitleManager. This script has a lot of other classes that are inherited from this, and has 1 main function to print subtitles to the screen. Most of the subtitles are the voices of the main character, but there are some other character’s subtitles. I want these character’s subtitles to be in different color than the main character’s. Since I have one main function to print subtitles, I used parameters.
protected void BypassSubtitle(string text, float duration, bool differentColor, Color newColor)
As you can see, we have a boolean variable, script changes the color of the subtitle to newColor variable, or default Color.white variable according to that boolean.
My question is, in some scripts, when I don’t want to change the subtitle color, I do not want to pass the last 2 parameters while calling the function. When I write:
BypassSubtitle("blabla", 3.0f);
I get errors that say the function can’t take two parameters, as it is obvious that I have 4 parameters so I have to do:
BypassSubtitle("blabla", 3.0f, false, Color.white);
So over here, eventhough I won’t be changing the color to another color, I still have to pass any Color parameter for the function to work, I am curious, can this cause overheads? Because actually I have 7-8 parameters, which are situation dependant, and also I have AudioManager which uses parameters too. So I though passing unnecessary parameters can cause performance issues, but I don’t know how not to call the function without the parameters that won’t be used. Any ideas? Thanks