I have a game wherein there are 2 playable characters, and you can switch between them for different things. I’m extremely new to coding and Unity Hub as a whole, so I used a tutorial to show me how to make a player swap code, and it looks like this:
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class PlayerSwitch : MonoBehaviour
{
public PlayerMovement playerMovement;
public PlayerMovement player2Movement;
public bool player1Active = true;
// Update is called once per frame
void Update()
{
if(Input.GetKeyDown(KeyCode.LeftShift))
{
SwitchPlayer();
}
}
public void SwitchPlayer()
{
if (player1Active)
{
playerMovement.enabled = false;
player2Movement.enabled = true;
player1Active = false;
}
else
{
playerMovement.enabled = true;
player2Movement.enabled = false;
player1Active = true;
}
}
}
This code lets you switch between players, but I don’t know what to add for you to be able to play both at once at the press of a key, or if it’s something I have to change in Unity rather than change the code.