Hi to all!
I’m working on a top-down shooter, and i’m doing good, but till now I didn’t care about the code repetition, and I made 5 powerups with pretty much the same script, with some little differences.
What I want to do now is to make a single script, who takes all the references it needs, and calls the right methods to apply the right powerup.
To activate bonuses, I’m trying to use a simple code like this one:
public void BonusON(string bonusName)
{
bonusDuration = GameObject.FindGameObjectWithTag(bonusName)
.GetComponent<scriptName>.bonusDuration;
//other code
}
What i’m trying to do is to reproduce something I saw while I was learning PHP, like dinamically obtaining a variable name using another variable value, then use the variable name to call a different method I prepared before… I made a research online to find if this way could be used in c# as well, but without luck.
What I surely need to know is if there’s a way to use the GetComponent method as I wrote above, so giving it a variable and letting it use that variable value as a component name.
Or, if there’s a simpler way, of course.