- Home /
Multiple players on single controller
I'm working on a game where you have multiple (3) characters, which are all controlled by a single player. Something like the Lost Vikings. How can I isolate the input so that only one moves at a time, and when a certain key is pressed, the control shifts to other charcter?
Answer by by0log1c · Feb 25, 2011 at 04:26 AM
What I'd do:
- create a built-in array characterList holding characters GameObjects.
- create a private boolean variable isActive, or something.
create a int variable activePlayer or something.
character [0] has isActive = true. other characters have it to false.
- in the Update() of the character script, only process Input if isActive==true.
every time player hit a certain key,go to next activePlayer:int; activePlayer++;
in the Update() of the character script, if isActive==false, make the character follow the active one.
something like that. Of course there's plenty of(better) way to do this but its definitly feasible.
Thank's that worked out. If it is inactive I just leave them standing there. I had to do a little tweaking, because just disabling the control input processing kept them going ins$$anonymous$$d of stopping them...
Answer by cregox · Feb 25, 2011 at 01:38 AM
From my experience, it's much easier to leave all the characters being controlled at same time and just keep 2 of them off the screen. When you switch, just change positions. I know it's hackish, but it works.
Can't really do that. The characters will interact with each other. By the way, it is 3rd person view...
Your answer
![](https://koobas.hobune.stream/wayback/20220613110146im_/https://answers.unity.com/themes/thub/images/avi.jpg)