54 lines
1.4 KiB
C#
54 lines
1.4 KiB
C#
using System;
|
|
using Unity.Cinemachine;
|
|
using UnityEngine;
|
|
|
|
public class PlayerSwitcher : MonoBehaviour
|
|
{
|
|
[SerializeField] private CinemachineCamera cam;
|
|
[Header("Players")]
|
|
[SerializeField] private Player player1;
|
|
[SerializeField] private AutomatedPlayer player1AI;
|
|
[SerializeField] private Player player2;
|
|
[SerializeField] private AutomatedPlayer player2AI;
|
|
|
|
[Header("Switch Cooldowns")]
|
|
[SerializeField] private float switchCooldown;
|
|
private float currentSwitchCooldown;
|
|
|
|
|
|
private void Update()
|
|
{
|
|
if (Input.GetKeyDown(KeyCode.E) && currentSwitchCooldown <= 0f)
|
|
{
|
|
SwitchPlayers(player1, player1AI, player2, player2AI);
|
|
currentSwitchCooldown = switchCooldown;
|
|
}
|
|
|
|
if (currentSwitchCooldown > 0f)
|
|
{
|
|
currentSwitchCooldown -= Time.deltaTime;
|
|
}
|
|
}
|
|
|
|
public void SwitchPlayers(Player playerA, AutomatedPlayer playerAAI, Player playerB, AutomatedPlayer playerBAI)
|
|
{
|
|
cam.Follow = playerB.transform;
|
|
playerAAI.enabled = true;
|
|
playerA.enabled = false;
|
|
playerB.enabled = true;
|
|
playerBAI.enabled = false;
|
|
(playerB.transform.position, playerAAI.transform.position) = (playerAAI.transform.position, playerB.transform.position);
|
|
player1 = playerB;
|
|
player1AI = playerBAI;
|
|
player2 = playerA;
|
|
player2AI = playerAAI;
|
|
foreach (Ability ability in playerA.stats.abilities)
|
|
{
|
|
ability.thisEntity = playerAAI;
|
|
}
|
|
foreach (Ability ability in playerBAI.stats.abilities)
|
|
{
|
|
ability.thisEntity = playerB;
|
|
}
|
|
}
|
|
}
|