Multiple Aircraft/Vehicles control question

Hi,

I’m learning C# and I was wondering if someone could explain something basic for me.

I have made a bunch of aircraft scripts that work great
I have now rigged multiple aircraft and have a few lined up on the runway.

The problem I have is when I get in to any of the aircraft all of the aircraft are controlled via the same input which means they all controlled/move at the same time.

How do I make the input controls work only for the aircraft that I enter? Does each aircraft need its own input script?

They can all use the same script. You just need to implement a system where unless the player is using that aircraft, they are disabled.

I have an enter/exit aircraft script - i’m guessing this would be the best place to do this?

Do you have any example code that I could use to get started?

It depends on how your scripts work. A simple option would be to just have the aircraft script disabled until the player enters it and disable it when the player leaves. That way, Unity won’t call the update methods on the monobehaviour unless the player is in the aircraft.

Yeah, what @WarmedxMints_1 says most likely is the simpliest: disable who isn’t playable.

But another approach is to have a player inspect items that they get into to see if they are controllable, and when they are, the player supplies its input adaptor to the object and then that one object will fly. Of course you would remove that adaptor when the player steps out of the vehicle. That way if you get out of an airplane midair, it will keep flying but without any input, just like GTA:SA.