In my game there's a Unit class, which all soldiers use. Not all soldiers have special abilities which require unique class components (like Stealth class). Special abilities either exist on a unit from the start, or never.
Special classes like Stealth are monobehaviour classes which provide specific functionality, and the fact a unit is or is not Stealth will need referenced by other classes. For example, the classes which handle unit shooting and detection must check whether a unit in proximity is stealth. I'm wondering what is the best way to handle this case with Unity, given components?
Right now the Unit class' Start function checks if the special class exists, and assigns a private boolean to true. This boolean can only get accessed by a get function. Does this make sense for more easily readable and secure code? Or is it overengineering?
private bool isStealth;
if (GetComponent<Stealth>())
{
isStealth = true;
}
public bool IsStealth()
{
return isStealth;
}
Stealth
class look like? \$\endgroup\$