UNITY3D: Change player control to a target model (FPS)

c#, unity-game-engine

Solution

This is pretty simple, in concept. Just have the NPC similar to the player class, in that it accepts control whenever something is true. For example:

class NPC {
static bool isBeingControlled = false;
public void OnUpdate() {
    if (isBeingControlled)
    {
        //set camera position to NPC position (make sure you're using NPC as an instantiated class)
        //accept key input WASD or whatever you are using and move NPC according to input.
    }
}

}

You'll have to instantiate NPC for each NPC you have in your game.

Problem

I am developing a small game prototype in Unity 3.5.5f - in which the player controls a small mind controlling alien. The player needs to be able to take control of a target human NPC, switching all camera and controls to the human in question. N.B. All of my code, thus far, is in C#. I have two ideas on how to progress, which one is more feasible? (I'm happy to listen to alternative ideas) - Each human in the level has a deactivated FPS controller script (and accompanying scripts). These scripts are activated when controlled (disabling the alien's scripts for the duration). - Detach the current scripts from the alien and attach them to the target human. The pros and cons as far as I seem them: - Can have separate alien/human controls scripts (i.e. don't need to use States for input - e.g. can fire a gun whilst human, instead of melee as an alien on LMB). This method is very clusterfucky. - This method is clean, but the code file for the player will be much larger as I cannot separate the input code as easily. EDIT: A friend has pointed out, yes the NPCs have scripts of their own which would need to be disabled.

Original source