How to find and use a certain script without using GetComponent?

I’m currently working on a system for the player to switch between different vehicles. When the player moves inside the trigger collider and presses a button, they become a child of the vehicle, the movement script on the player is disabled, and the vehicle’s movement script is enabled.

My problem is that my VehicleManager script only knows what the movement script on the vehicle is if I use the GetComponent function and physically type in the name of the script. In what way could I have the VehicleManager figure out which movement script is attached to each different vehicle?

Maybe add a parent class to all your vehicle movement scripts is a better way.

For exsample:

VehicleMovement - Parent Class

  • Car
  • Bike
  • Bus

All these vehicle inherit VehicleMovement and share some common functions, Move, Stop, Turn… etc

Then in your VehicleManager, use the VehicleMovement instead of specific vehicle