uh you can switch players now
This commit is contained in:
parent
a0bfc600ef
commit
cb4470f2d6
11 changed files with 582 additions and 235 deletions
|
|
@ -1,38 +1,49 @@
|
|||
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))
|
||||
if (Input.GetKeyDown(KeyCode.E) && currentSwitchCooldown <= 0f)
|
||||
{
|
||||
SwitchPlayers();
|
||||
if (player1.isActiveAndEnabled)
|
||||
{
|
||||
SwitchPlayers(player1, player1AI, player2, player2AI);
|
||||
}
|
||||
else
|
||||
{
|
||||
SwitchPlayers(player2, player2AI, player1, player1AI);
|
||||
}
|
||||
currentSwitchCooldown = switchCooldown;
|
||||
}
|
||||
|
||||
if (currentSwitchCooldown > 0f)
|
||||
{
|
||||
currentSwitchCooldown -= Time.deltaTime;
|
||||
}
|
||||
}
|
||||
|
||||
public void SwitchPlayers() //i bet if i made it a parameter i wouldn't have to make an if statement. but it's literally 5 am and i'm lazy
|
||||
public void SwitchPlayers(Player playerA, AutomatedPlayer playerAAI, Player playerB, AutomatedPlayer playerBAI)
|
||||
{
|
||||
if (player1.enabled)
|
||||
{
|
||||
player1AI.enabled = true;
|
||||
player1.enabled = false;
|
||||
player2.enabled = true;
|
||||
player2AI.enabled = false;
|
||||
(player2.transform.position, player1AI.transform.position) = (player1AI.transform.position, player2.transform.position);
|
||||
}
|
||||
else
|
||||
{
|
||||
player2AI.enabled = true;
|
||||
player2.enabled = false;
|
||||
player1.enabled = true;
|
||||
player1AI.enabled = false;
|
||||
(player1.transform.position, player2AI.transform.position) = (player2AI.transform.position, player1.transform.position);
|
||||
}
|
||||
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);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue