switch character

,Hi guys . I have two characters in the game I want to change between them with the press of a button while the game is running. The camera also goes to the other player, while the first player follows the second player. I know that the question is a little bit complicated, but I need an answer, thank you all.

Create a camera script that switches the camera focus… something like this:

public Transform[] targets;
int which = 0;

void Start()
{
    which = 0;
}

void Update()
{
    transform.position = targets[which].position;
    if ()
    {
        which++;
        if (which == 2) which = 0;
    }
}

Of course you should add offsets and lerping… but that is the basic idea. As for controlling… the characters… I would add a child gameobject slightly behind each player to about where you want the other character to follow. I would then build two separate “motor” scripts on the characters. On one would be player controls and on the other would be AI navigation controls. When the user switches players disable one and enable the other. For the AI - navmesh agent, set the target to the child object of the other character.