Trying to pass two different classes to a destination class with the least amount of code

The scenario is this -

One class is AirController - it has a bunch of specific values that need to be accessed, especially a scriptable object soAir, which holds a lot of it’s definitions like airSpeed or maxHealth specific to air vehicles.

The seoond class is GroundVehicleController - it has it’s own ScriptableObject called soGroundVehicle, which holds values like speed and maxHealth specific to ground vehicles.

Now, here’s the issue - I want to be able to shield each of these units and use the same shield methods on each like InitShield(), DeployShield(), etc, but I just don’t know how to do this any better way than having two scripts or inheriting one script from the other for the shields.

For instance, to get the definition of the class to the Init method, I would write something like this for the shielded Air unit:

public void InitShield(soAir _soAir, AirController _controller)
{
soRef = _soAir;
controller = _controller;
CreateShield (controller);
}

but if it was a shielded vehicle, i would need to do:

public void InitShield(soGroundVehicle _soGroundVehicle, GroundController _controller)
{
soRef = _soGroundVehicle;
controller = _controller;
CreateShield(controller);
}

It would be great to combine these two scripts so that the classes I am passing are more generic (and yes, I use this word intentionally), but I’m not sure how to do this. I know I could have a bool isAir or something too, but this would just double the code in the destination class.

I hope this example and question make sense and thank you for any help you can provide.

You could use a Map to store the data for each type of vehicle, then pass the Map instead of the class.

A typical way would be to split off all shield-related stuff into a Shield class. In Unity you might make it a monobehaviour, which means it would set on gameObjects next to the land or air controller scripts. Those 2 scripts would reach out to it (for example in Start() they could use myShieldScript=getComponent<Shield>();, where null means you have no shield).

A more traditional OOP might have air and land include the shield class as a member and have them each inherit an interface like Shieldable. And so on.

Interfaces were the ticket @Owen-Reynolds ! Thank you for the suggestion - that worked out perfectly. I use them a lot in my code, but hadn’t considered that I could use them for this. I set up an IShieldable interface, and used it in each of the classes then called an InitShieldHealth() method which all shared. Worked like a charm. Thanks again!