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?
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.
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.