Let’s say I’m making a car and I make a script for a generic gauge. My car has a data class with carData.speed and carData.engineRPM variables. The gauge has a float variable pointerValue that controls the gauge indication. Is there a way I could just assign the same gauge script to every gauge and just set the pointerValue to car.speed or car.EngineRPM in the inspector?
You could use an interface (or interfaces).
For instance you could make an interface called IRPMProvider and have your car’s driving script implement it.
When your gauge script Start()s up it searches the current GameObject for Monobehaviors that implement the IRPMProvider interface, and then they call it to get their RPM.
Google around for examples of using interfaces in Unity. It’s pretty slick. If you made other types of vehicles, all they would need to do is implement the IRPMProvider interface and then the same gauge can read it.
If you want another gauge design (digital vs analog), make two of them and make them both look for the IRPMProvider.
EDIT: here’s a quick discussion link: Unity Tip: Utilize C# interfaces to simplify development - Lowscope