added comments and organized project files
This commit is contained in:
8
Assets/Animations/Game.meta
Normal file
8
Assets/Animations/Game.meta
Normal file
@@ -0,0 +1,8 @@
|
|||||||
|
fileFormatVersion: 2
|
||||||
|
guid: 586436400e0b7d64095ccd5e7a0f6f55
|
||||||
|
folderAsset: yes
|
||||||
|
DefaultImporter:
|
||||||
|
externalObjects: {}
|
||||||
|
userData:
|
||||||
|
assetBundleName:
|
||||||
|
assetBundleVariant:
|
||||||
@@ -147,7 +147,8 @@ TextureImporter:
|
|||||||
secondaryTextures: []
|
secondaryTextures: []
|
||||||
spriteCustomMetadata:
|
spriteCustomMetadata:
|
||||||
entries: []
|
entries: []
|
||||||
nameFileIdTable: {}
|
nameFileIdTable:
|
||||||
|
backgroundddddd-export_0: -6475902312293128869
|
||||||
mipmapLimitGroupName:
|
mipmapLimitGroupName:
|
||||||
pSDRemoveMatte: 0
|
pSDRemoveMatte: 0
|
||||||
userData:
|
userData:
|
||||||
|
|||||||
@@ -4817,6 +4817,14 @@ PrefabInstance:
|
|||||||
propertyPath: timer
|
propertyPath: timer
|
||||||
value:
|
value:
|
||||||
objectReference: {fileID: 6442071445436727403}
|
objectReference: {fileID: 6442071445436727403}
|
||||||
|
- target: {fileID: 4907520530801696033, guid: e3c570bb90d434e809aca2a339dadf5d, type: 3}
|
||||||
|
propertyPath: m_LocalPosition.x
|
||||||
|
value: 15.35
|
||||||
|
objectReference: {fileID: 0}
|
||||||
|
- target: {fileID: 4907520530801696033, guid: e3c570bb90d434e809aca2a339dadf5d, type: 3}
|
||||||
|
propertyPath: m_LocalPosition.y
|
||||||
|
value: -0.77
|
||||||
|
objectReference: {fileID: 0}
|
||||||
- target: {fileID: 6537344883611667483, guid: e3c570bb90d434e809aca2a339dadf5d, type: 3}
|
- target: {fileID: 6537344883611667483, guid: e3c570bb90d434e809aca2a339dadf5d, type: 3}
|
||||||
propertyPath: m_Camera
|
propertyPath: m_Camera
|
||||||
value:
|
value:
|
||||||
@@ -4865,12 +4873,17 @@ PrefabInstance:
|
|||||||
propertyPath: m_LocalEulerAnglesHint.z
|
propertyPath: m_LocalEulerAnglesHint.z
|
||||||
value: 0
|
value: 0
|
||||||
objectReference: {fileID: 0}
|
objectReference: {fileID: 0}
|
||||||
|
- target: {fileID: 7889484632530234123, guid: e3c570bb90d434e809aca2a339dadf5d, type: 3}
|
||||||
|
propertyPath: leaderboardIconPrefab
|
||||||
|
value:
|
||||||
|
objectReference: {fileID: 367874778634194597, guid: d9a95e84f7261408c84253a380f8af08, type: 3}
|
||||||
- target: {fileID: 8079215911535814924, guid: e3c570bb90d434e809aca2a339dadf5d, type: 3}
|
- target: {fileID: 8079215911535814924, guid: e3c570bb90d434e809aca2a339dadf5d, type: 3}
|
||||||
propertyPath: m_Name
|
propertyPath: m_Name
|
||||||
value: HealthCanvas
|
value: HealthCanvas
|
||||||
objectReference: {fileID: 0}
|
objectReference: {fileID: 0}
|
||||||
m_RemovedComponents: []
|
m_RemovedComponents: []
|
||||||
m_RemovedGameObjects: []
|
m_RemovedGameObjects:
|
||||||
|
- {fileID: 4148327129846918965, guid: e3c570bb90d434e809aca2a339dadf5d, type: 3}
|
||||||
m_AddedGameObjects: []
|
m_AddedGameObjects: []
|
||||||
m_AddedComponents: []
|
m_AddedComponents: []
|
||||||
m_SourcePrefab: {fileID: 100100000, guid: e3c570bb90d434e809aca2a339dadf5d, type: 3}
|
m_SourcePrefab: {fileID: 100100000, guid: e3c570bb90d434e809aca2a339dadf5d, type: 3}
|
||||||
|
|||||||
8
Assets/Scripts/Game.meta
Normal file
8
Assets/Scripts/Game.meta
Normal file
@@ -0,0 +1,8 @@
|
|||||||
|
fileFormatVersion: 2
|
||||||
|
guid: cb25285062358bf41aa26cc8ca26b120
|
||||||
|
folderAsset: yes
|
||||||
|
DefaultImporter:
|
||||||
|
externalObjects: {}
|
||||||
|
userData:
|
||||||
|
assetBundleName:
|
||||||
|
assetBundleVariant:
|
||||||
@@ -7,7 +7,7 @@ public class PlayerCardCreator : MonoBehaviour
|
|||||||
|
|
||||||
public GameObject playerJoinCardPrefab;
|
public GameObject playerJoinCardPrefab;
|
||||||
|
|
||||||
private void Awake()
|
private void Awake() // Ensures only one instance of PlayerCardCreator exists
|
||||||
{
|
{
|
||||||
if (Instance == null) Instance = this;
|
if (Instance == null) Instance = this;
|
||||||
else
|
else
|
||||||
@@ -16,7 +16,7 @@ public class PlayerCardCreator : MonoBehaviour
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public PlayerJoinCard CreateCard()
|
public PlayerJoinCard CreateCard() // Creates a player join card
|
||||||
{
|
{
|
||||||
GameObject card = Instantiate(playerJoinCardPrefab, transform);
|
GameObject card = Instantiate(playerJoinCardPrefab, transform);
|
||||||
return card.GetComponent<PlayerJoinCard>();
|
return card.GetComponent<PlayerJoinCard>();
|
||||||
@@ -3,7 +3,7 @@ using UnityEngine.EventSystems;
|
|||||||
|
|
||||||
public class EventSystemizer : MonoBehaviour
|
public class EventSystemizer : MonoBehaviour
|
||||||
{
|
{
|
||||||
private void Update()
|
private void Update() // Ensures only one instance of EventSystem exists
|
||||||
{
|
{
|
||||||
foreach (EventSystem system in FindObjectsByType<EventSystem>(FindObjectsSortMode.None))
|
foreach (EventSystem system in FindObjectsByType<EventSystem>(FindObjectsSortMode.None))
|
||||||
{
|
{
|
||||||
@@ -3,8 +3,8 @@ using UnityEngine;
|
|||||||
|
|
||||||
public class FallPlatform : MonoBehaviour
|
public class FallPlatform : MonoBehaviour
|
||||||
{
|
{
|
||||||
public float fallDelay = 2f;
|
public float fallDelay = 2f; // Delay before the platform falls
|
||||||
public float resetDelay = 4f;
|
public float resetDelay = 4f; // Delay before the platform resets
|
||||||
|
|
||||||
bool falling;
|
bool falling;
|
||||||
Rigidbody2D rb;
|
Rigidbody2D rb;
|
||||||
@@ -15,7 +15,7 @@ public class FallPlatform : MonoBehaviour
|
|||||||
defposition = transform.parent.position;
|
defposition = transform.parent.position;
|
||||||
rb = transform.parent.GetComponent<Rigidbody2D>();
|
rb = transform.parent.GetComponent<Rigidbody2D>();
|
||||||
}
|
}
|
||||||
private void OnTriggerEnter2D(Collider2D collision)
|
private void OnTriggerEnter2D(Collider2D collision) // Makes platform fall when player or another platform touch it
|
||||||
{
|
{
|
||||||
if (!falling && (collision.gameObject.CompareTag("Player") || collision.transform.GetChild(0).TryGetComponent(out FallPlatform _)))
|
if (!falling && (collision.gameObject.CompareTag("Player") || collision.transform.GetChild(0).TryGetComponent(out FallPlatform _)))
|
||||||
{
|
{
|
||||||
@@ -23,7 +23,7 @@ public class FallPlatform : MonoBehaviour
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private IEnumerator FallAfterDelay()
|
private IEnumerator FallAfterDelay() // Sets platform to fall and respawn
|
||||||
{
|
{
|
||||||
falling = true;
|
falling = true;
|
||||||
yield return new WaitForSeconds(fallDelay);
|
yield return new WaitForSeconds(fallDelay);
|
||||||
@@ -36,7 +36,7 @@ public class FallPlatform : MonoBehaviour
|
|||||||
|
|
||||||
//only resets the object script is attached to, need to fix so platform will reset with fall trigger object
|
//only resets the object script is attached to, need to fix so platform will reset with fall trigger object
|
||||||
// Use transform.parent to get the object it's attatched to
|
// Use transform.parent to get the object it's attatched to
|
||||||
private void Respawn()
|
private void Respawn() // Resets the platform position
|
||||||
{
|
{
|
||||||
falling = false;
|
falling = false;
|
||||||
rb.bodyType = RigidbodyType2D.Static;
|
rb.bodyType = RigidbodyType2D.Static;
|
||||||
@@ -6,7 +6,6 @@ using UnityEngine.InputSystem;
|
|||||||
public class GameManager : MonoBehaviour
|
public class GameManager : MonoBehaviour
|
||||||
{
|
{
|
||||||
public static GameManager Instance { get; private set; }
|
public static GameManager Instance { get; private set; }
|
||||||
public int maxLives = 3;
|
|
||||||
public float time = 180f;
|
public float time = 180f;
|
||||||
public delegate void GameEvent();
|
public delegate void GameEvent();
|
||||||
public event GameEvent StartGameEvent;
|
public event GameEvent StartGameEvent;
|
||||||
@@ -14,14 +13,22 @@ public class GameManager : MonoBehaviour
|
|||||||
public static List<GameObject> players = new List<GameObject>();
|
public static List<GameObject> players = new List<GameObject>();
|
||||||
public static List<Color> playerColors = new List<Color>();
|
public static List<Color> playerColors = new List<Color>();
|
||||||
public float offset = 1f;
|
public float offset = 1f;
|
||||||
|
|
||||||
public static bool music = true;
|
public static bool music = true;
|
||||||
|
|
||||||
public bool gameOver = false;
|
public bool gameOver = false;
|
||||||
public GameTimer gameTimer;
|
public GameTimer gameTimer;
|
||||||
public static Dictionary<GameObject, float> playerHoldTimes = new Dictionary<GameObject, float>();
|
public static Dictionary<GameObject, float> playerHoldTimes = new Dictionary<GameObject, float>();
|
||||||
|
public static GameMode gameMode = GameMode.freeForAll; // loads a default gamemode as a safety net
|
||||||
|
public static string map = "Platformer With Headroom"; // loads a default map as a safety net
|
||||||
|
public Vector2 spawnPosition;
|
||||||
|
public Vector2 hatSpawnPosition;
|
||||||
|
public enum GameMode
|
||||||
|
{
|
||||||
|
freeForAll,
|
||||||
|
keepAway,
|
||||||
|
obstacleCourse
|
||||||
|
}
|
||||||
|
|
||||||
private void Awake()
|
private void Awake() // Ensures only one instance of GameManager exists
|
||||||
{
|
{
|
||||||
if (Instance == null)
|
if (Instance == null)
|
||||||
{
|
{
|
||||||
@@ -33,20 +40,20 @@ public class GameManager : MonoBehaviour
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private void Start()
|
private void Start() // Starts the game and music
|
||||||
{
|
{
|
||||||
MusicManager.Instance.StartPlaylist();
|
MusicManager.Instance.StartPlaylist();
|
||||||
StartGame();
|
StartGame();
|
||||||
}
|
}
|
||||||
|
|
||||||
public void StartGame()
|
public void StartGame() // Sets up the proper gamemode
|
||||||
{
|
{
|
||||||
GameManager.playerHoldTimes.Clear();
|
GameManager.playerHoldTimes.Clear();
|
||||||
if (GameManager.players.Count == 0) return;
|
if (GameManager.players.Count == 0) return;
|
||||||
|
|
||||||
StartGameEvent?.Invoke();
|
StartGameEvent?.Invoke();
|
||||||
print("Starting game with mode: " + gameMode + " and map: " + map);
|
print("Starting game with mode: " + gameMode + " and map: " + map);
|
||||||
if (gameMode == GameMode.freeForAll)
|
if (gameMode == GameMode.freeForAll) // Sets up the game for free for all mode
|
||||||
{
|
{
|
||||||
foreach (GameObject player in players)
|
foreach (GameObject player in players)
|
||||||
{
|
{
|
||||||
@@ -54,7 +61,7 @@ public class GameManager : MonoBehaviour
|
|||||||
player.GetComponent<Damageable>().lives = 5;
|
player.GetComponent<Damageable>().lives = 5;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (gameMode == GameMode.keepAway)
|
if (gameMode == GameMode.keepAway) // Sets up the game for keep away mode
|
||||||
{
|
{
|
||||||
gameTimer.startTime = time;
|
gameTimer.startTime = time;
|
||||||
gameTimer.StartTimer();
|
gameTimer.StartTimer();
|
||||||
@@ -64,7 +71,7 @@ public class GameManager : MonoBehaviour
|
|||||||
player.GetComponent<Damageable>().lives = 0;
|
player.GetComponent<Damageable>().lives = 0;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (gameMode == GameMode.obstacleCourse)
|
if (gameMode == GameMode.obstacleCourse) // Sets up the game for obstacle course mode
|
||||||
{
|
{
|
||||||
foreach (GameObject player in players)
|
foreach (GameObject player in players)
|
||||||
{
|
{
|
||||||
@@ -73,21 +80,9 @@ public class GameManager : MonoBehaviour
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public enum GameMode
|
public void PlayerDied(Damageable player) // Handles player deaths for the respective gamemode
|
||||||
{
|
{
|
||||||
freeForAll,
|
if (gameMode == GameMode.freeForAll) // Respawns player if they have lives left
|
||||||
keepAway,
|
|
||||||
obstacleCourse
|
|
||||||
}
|
|
||||||
|
|
||||||
public static GameMode gameMode = GameMode.freeForAll; // loads a default gamemode as a safety net
|
|
||||||
public static string map = "Platformer With Headroom"; // loads a default map as a safety net
|
|
||||||
public Vector2 spawnPosition;
|
|
||||||
public Vector2 hatSpawnPosition;
|
|
||||||
|
|
||||||
public void PlayerDied(Damageable player)
|
|
||||||
{
|
|
||||||
if (gameMode == GameMode.freeForAll)
|
|
||||||
{
|
{
|
||||||
player.lives--;
|
player.lives--;
|
||||||
if (player.lives <= 0 && !gameOver)
|
if (player.lives <= 0 && !gameOver)
|
||||||
@@ -95,7 +90,7 @@ public class GameManager : MonoBehaviour
|
|||||||
player.gameObject.SetActive(false);
|
player.gameObject.SetActive(false);
|
||||||
if (AlivePlayers().Count <= 1)
|
if (AlivePlayers().Count <= 1)
|
||||||
{
|
{
|
||||||
GameOver();
|
GameOver(); // Winner is called when only one player is left
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
@@ -103,7 +98,7 @@ public class GameManager : MonoBehaviour
|
|||||||
RespawnPlayer(player.gameObject);
|
RespawnPlayer(player.gameObject);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (gameMode == GameMode.keepAway)
|
if (gameMode == GameMode.keepAway) // Always respawns player regardless of lives
|
||||||
{
|
{
|
||||||
RespawnPlayer(player.gameObject);
|
RespawnPlayer(player.gameObject);
|
||||||
}
|
}
|
||||||
@@ -113,7 +108,7 @@ public class GameManager : MonoBehaviour
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private void RespawnPlayer(GameObject player)
|
private void RespawnPlayer(GameObject player) // Respawns player at the spawn point and resets health
|
||||||
{
|
{
|
||||||
RespawnOnTriggerEnter respawnScript = player.GetComponent<RespawnOnTriggerEnter>();
|
RespawnOnTriggerEnter respawnScript = player.GetComponent<RespawnOnTriggerEnter>();
|
||||||
if (respawnScript != null)
|
if (respawnScript != null)
|
||||||
@@ -124,18 +119,19 @@ public class GameManager : MonoBehaviour
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public void GameOver()
|
public void GameOver() // Ends game and displays winner
|
||||||
{
|
{
|
||||||
gameOver = true;
|
gameOver = true;
|
||||||
EndGameEvent?.Invoke();
|
EndGameEvent?.Invoke();
|
||||||
if (gameMode == GameMode.freeForAll)
|
if (gameMode == GameMode.freeForAll) // Last player alive wins
|
||||||
{
|
{
|
||||||
print(AlivePlayers()[0].name + " is the winner");
|
GameObject winner = AlivePlayers()[0];
|
||||||
FindFirstObjectByType<PlayerCameraMovement>().WinScene(AlivePlayers()[0]);
|
print(winner.name + " is the winner");
|
||||||
WinScreen.Instance.ShowWinScreen(players.IndexOf(AlivePlayers()[0]) + 1);
|
FindFirstObjectByType<PlayerCameraMovement>().WinScene(winner);
|
||||||
|
WinScreen.Instance.ShowWinScreen(players.IndexOf(winner) + 1);
|
||||||
FindFirstObjectByType<LifeDisplayManager>().HideLifeDisplay();
|
FindFirstObjectByType<LifeDisplayManager>().HideLifeDisplay();
|
||||||
}
|
}
|
||||||
if (gameMode == GameMode.keepAway)
|
if (gameMode == GameMode.keepAway) // Player with the most time holding the hat wins
|
||||||
{
|
{
|
||||||
GameObject winner = null;
|
GameObject winner = null;
|
||||||
float maxHoldTime = 0f;
|
float maxHoldTime = 0f;
|
||||||
@@ -157,7 +153,7 @@ public class GameManager : MonoBehaviour
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public List<GameObject> AlivePlayers()
|
public List<GameObject> AlivePlayers() // Returns a list of all players that are alive
|
||||||
{
|
{
|
||||||
List<GameObject> alivePlayers = new();
|
List<GameObject> alivePlayers = new();
|
||||||
|
|
||||||
@@ -169,7 +165,7 @@ public class GameManager : MonoBehaviour
|
|||||||
return alivePlayers;
|
return alivePlayers;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void UpdatePlayerHoldTime(GameObject player, float holdTime)
|
public void UpdatePlayerHoldTime(GameObject player, float holdTime) // Finds each players hold time and updates the leaderboard
|
||||||
{
|
{
|
||||||
if (playerHoldTimes.ContainsKey(player))
|
if (playerHoldTimes.ContainsKey(player))
|
||||||
{
|
{
|
||||||
@@ -18,7 +18,7 @@ public class GameTimer : MonoBehaviour
|
|||||||
UpdateTimerDisplay();
|
UpdateTimerDisplay();
|
||||||
}
|
}
|
||||||
|
|
||||||
private void Update()
|
private void Update() // Updates the timer to show the time remaining
|
||||||
{
|
{
|
||||||
if (timerRunning)
|
if (timerRunning)
|
||||||
{
|
{
|
||||||
@@ -35,7 +35,7 @@ public class GameTimer : MonoBehaviour
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public void StartTimer()
|
public void StartTimer() // Starts the timer
|
||||||
{
|
{
|
||||||
if (!timerRunning)
|
if (!timerRunning)
|
||||||
{
|
{
|
||||||
@@ -44,14 +44,14 @@ public class GameTimer : MonoBehaviour
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private void UpdateTimerDisplay()
|
private void UpdateTimerDisplay() // Formats and sets the time remaining
|
||||||
{
|
{
|
||||||
int minutes = Mathf.FloorToInt(timeRemaining / 60);
|
int minutes = Mathf.FloorToInt(timeRemaining / 60);
|
||||||
int seconds = Mathf.FloorToInt(timeRemaining % 60);
|
int seconds = Mathf.FloorToInt(timeRemaining % 60);
|
||||||
timer.text = string.Format("{0}:{1:D2}", minutes, seconds);
|
timer.text = string.Format("{0}:{1:D2}", minutes, seconds);
|
||||||
}
|
}
|
||||||
|
|
||||||
private void OnTimerEnd()
|
private void OnTimerEnd() // Ends the game when the time runs out
|
||||||
{
|
{
|
||||||
GameManager.Instance.GameOver();
|
GameManager.Instance.GameOver();
|
||||||
}
|
}
|
||||||
@@ -2,7 +2,7 @@ using UnityEngine;
|
|||||||
|
|
||||||
public class HatRespawn : MonoBehaviour
|
public class HatRespawn : MonoBehaviour
|
||||||
{
|
{
|
||||||
void OnTriggerEnter2D(Collider2D collision)
|
void OnTriggerEnter2D(Collider2D collision) // Respawns the hat to the hat spawn position if it falls out of bounds
|
||||||
{
|
{
|
||||||
if (collision.gameObject.CompareTag("Platformer Hazard"))
|
if (collision.gameObject.CompareTag("Platformer Hazard"))
|
||||||
{
|
{
|
||||||
@@ -18,7 +18,7 @@ public class HealthBarManager : MonoBehaviour
|
|||||||
GameManager.Instance.EndGameEvent -= OnGameEnd;
|
GameManager.Instance.EndGameEvent -= OnGameEnd;
|
||||||
}
|
}
|
||||||
|
|
||||||
void Update()
|
void Update() // Updates position of health bars to follow each player
|
||||||
{
|
{
|
||||||
foreach (var kvp in playerHealthBars)
|
foreach (var kvp in playerHealthBars)
|
||||||
{
|
{
|
||||||
@@ -26,12 +26,11 @@ public class HealthBarManager : MonoBehaviour
|
|||||||
if (player == null) continue;
|
if (player == null) continue;
|
||||||
|
|
||||||
GameObject healthBar = kvp.Value;
|
GameObject healthBar = kvp.Value;
|
||||||
//healthBar.GetComponent<TerribleHealthBarScript>().fullHealthColor = GameManager.playerColors[GameManager.players.IndexOf(player)]; // Color health bars
|
|
||||||
healthBar.transform.SetPositionAndRotation(new Vector3(player.transform.position.x, player.transform.position.y + 1.5f, player.transform.position.z), Quaternion.identity);
|
healthBar.transform.SetPositionAndRotation(new Vector3(player.transform.position.x, player.transform.position.y + 1.5f, player.transform.position.z), Quaternion.identity);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private void OnGameStart()
|
private void OnGameStart() // Creates health bars for each player
|
||||||
{
|
{
|
||||||
foreach (GameObject player in GameManager.players)
|
foreach (GameObject player in GameManager.players)
|
||||||
{
|
{
|
||||||
@@ -45,7 +44,7 @@ public class HealthBarManager : MonoBehaviour
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private void OnGameEnd()
|
private void OnGameEnd() // Destroys the health bars when the game ends
|
||||||
{
|
{
|
||||||
foreach (var kvp in playerHealthBars)
|
foreach (var kvp in playerHealthBars)
|
||||||
{
|
{
|
||||||
@@ -6,7 +6,7 @@ public class InfiniteScroll : MonoBehaviour
|
|||||||
public float start;
|
public float start;
|
||||||
public float end;
|
public float end;
|
||||||
|
|
||||||
private void Update()
|
private void Update() // Moves the background
|
||||||
{
|
{
|
||||||
if (transform.position.x > end)
|
if (transform.position.x > end)
|
||||||
{
|
{
|
||||||
@@ -8,11 +8,11 @@ public class LeaderboardManager : MonoBehaviour
|
|||||||
|
|
||||||
[SerializeField] private GameObject playersParent;
|
[SerializeField] private GameObject playersParent;
|
||||||
[SerializeField] private GameObject playerPrefab;
|
[SerializeField] private GameObject playerPrefab;
|
||||||
[SerializeField] private GameObject lifePrefab;
|
[SerializeField] private GameObject leaderboardIconPrefab;
|
||||||
|
|
||||||
private Dictionary<GameObject, GameObject> playerIcons = new Dictionary<GameObject, GameObject>();
|
private Dictionary<GameObject, GameObject> playerIcons = new Dictionary<GameObject, GameObject>();
|
||||||
|
|
||||||
private void Awake()
|
private void Awake() // Ensures only one instance of LeaderboardManager exists
|
||||||
{
|
{
|
||||||
if (Instance == null)
|
if (Instance == null)
|
||||||
{
|
{
|
||||||
@@ -29,36 +29,28 @@ public class LeaderboardManager : MonoBehaviour
|
|||||||
InitializeLeaderboard();
|
InitializeLeaderboard();
|
||||||
}
|
}
|
||||||
|
|
||||||
private void InitializeLeaderboard()
|
private void InitializeLeaderboard() // Creates the leaderboard icons for each player
|
||||||
{
|
{
|
||||||
foreach (GameObject player in GameManager.players)
|
foreach (GameObject player in GameManager.players)
|
||||||
{
|
{
|
||||||
Transform parent = Instantiate(playerPrefab, playersParent.transform).transform;
|
Transform parent = Instantiate(playerPrefab, playersParent.transform).transform;
|
||||||
GameObject life = Instantiate(lifePrefab, parent);
|
GameObject leaderboardIcon = Instantiate(leaderboardIconPrefab, parent);
|
||||||
life.GetComponentInChildren<Image>().color = GameManager.playerColors[GameManager.players.IndexOf(player)];
|
leaderboardIcon.GetComponentInChildren<Image>().color = GameManager.playerColors[GameManager.players.IndexOf(player)];
|
||||||
playerIcons[player] = parent.gameObject;
|
playerIcons[player] = parent.gameObject;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public void UpdateLeaderboard()
|
public void UpdateLeaderboard() // Sorts the leaderboard based on player hold times
|
||||||
{
|
{
|
||||||
List<KeyValuePair<GameObject, float>> sortedList = new List<KeyValuePair<GameObject, float>>(GameManager.playerHoldTimes);
|
List<KeyValuePair<GameObject, float>> sortedList = new List<KeyValuePair<GameObject, float>>(GameManager.playerHoldTimes);
|
||||||
sortedList.Sort((pair1, pair2) => pair2.Value.CompareTo(pair1.Value));
|
sortedList.Sort((pair1, pair2) => pair2.Value.CompareTo(pair1.Value));
|
||||||
|
|
||||||
foreach (var player in sortedList)
|
foreach (var player in sortedList)
|
||||||
{
|
{
|
||||||
Debug.Log(player.Key.name + " : " + player.Value);
|
Debug.Log(player.Key.name + " : " + player.Value);
|
||||||
}
|
}
|
||||||
// Less fancy sorting system
|
|
||||||
|
|
||||||
foreach (var player in sortedList)
|
foreach (var player in sortedList)
|
||||||
{
|
{
|
||||||
playerIcons[player.Key].transform.SetSiblingIndex(sortedList.IndexOf(player));
|
playerIcons[player.Key].transform.SetSiblingIndex(sortedList.IndexOf(player));
|
||||||
}
|
}
|
||||||
|
|
||||||
//foreach (var key in GameManager.playerHoldTimes)
|
|
||||||
//{
|
|
||||||
// print(key.Key.name + " : " + key.Value);
|
|
||||||
// }
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -7,10 +7,9 @@ public class LifeDisplayManager : MonoBehaviour
|
|||||||
public GameObject players;
|
public GameObject players;
|
||||||
public GameObject playerPrefab;
|
public GameObject playerPrefab;
|
||||||
public GameObject lifePrefab;
|
public GameObject lifePrefab;
|
||||||
|
|
||||||
public Dictionary<Damageable, List<GameObject>> lifeDisplays = new Dictionary<Damageable, List<GameObject>>();
|
public Dictionary<Damageable, List<GameObject>> lifeDisplays = new Dictionary<Damageable, List<GameObject>>();
|
||||||
|
|
||||||
private void Start()
|
private void Start() // Creates life icons for each player
|
||||||
{
|
{
|
||||||
if (GameManager.gameMode == GameManager.GameMode.freeForAll)
|
if (GameManager.gameMode == GameManager.GameMode.freeForAll)
|
||||||
{
|
{
|
||||||
@@ -29,7 +28,7 @@ public class LifeDisplayManager : MonoBehaviour
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private void Update()
|
private void Update() // Updates the lives displayed based on player lives
|
||||||
{
|
{
|
||||||
foreach (Damageable damageable in lifeDisplays.Keys)
|
foreach (Damageable damageable in lifeDisplays.Keys)
|
||||||
{
|
{
|
||||||
@@ -40,7 +39,7 @@ public class LifeDisplayManager : MonoBehaviour
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public void HideLifeDisplay()
|
public void HideLifeDisplay() // Hides life display
|
||||||
{
|
{
|
||||||
players.SetActive(false);
|
players.SetActive(false);
|
||||||
}
|
}
|
||||||
@@ -10,7 +10,7 @@ public class MapSelect : MonoBehaviour
|
|||||||
maps = GetComponent<ToggleGroup>();
|
maps = GetComponent<ToggleGroup>();
|
||||||
}
|
}
|
||||||
|
|
||||||
void Update()
|
void Update() // Sets the map based on the selected toggle
|
||||||
{
|
{
|
||||||
Toggle toggle = maps.GetFirstActiveToggle();
|
Toggle toggle = maps.GetFirstActiveToggle();
|
||||||
GameManager.map = toggle.name;
|
GameManager.map = toggle.name;
|
||||||
@@ -10,7 +10,7 @@ public class ModeSelect : MonoBehaviour
|
|||||||
maps = GetComponent<ToggleGroup>();
|
maps = GetComponent<ToggleGroup>();
|
||||||
}
|
}
|
||||||
|
|
||||||
void Update()
|
void Update() // Updates the game mode based on the selected toggle
|
||||||
{
|
{
|
||||||
Toggle toggle = maps.GetFirstActiveToggle();
|
Toggle toggle = maps.GetFirstActiveToggle();
|
||||||
if (toggle.name == "Free-For-All")
|
if (toggle.name == "Free-For-All")
|
||||||
@@ -6,16 +6,16 @@ public class MovingPlatform : MonoBehaviour
|
|||||||
public int startPoint;
|
public int startPoint;
|
||||||
public Transform[] points;
|
public Transform[] points;
|
||||||
public float speed;
|
public float speed;
|
||||||
|
|
||||||
private int i;
|
private int i;
|
||||||
|
|
||||||
void Start()
|
void Start() // Sets the initial position of the platform
|
||||||
{
|
{
|
||||||
transform.position = points[startPoint].position;
|
transform.position = points[startPoint].position;
|
||||||
}
|
}
|
||||||
|
|
||||||
void Update()
|
void Update()
|
||||||
{
|
{
|
||||||
|
// If the platform is close to the target point, it starts moving to the next one
|
||||||
if (Vector2.Distance(transform.position, points[i].position) < 0.02f)
|
if (Vector2.Distance(transform.position, points[i].position) < 0.02f)
|
||||||
{
|
{
|
||||||
i++;
|
i++;
|
||||||
@@ -24,7 +24,7 @@ public class MovingPlatform : MonoBehaviour
|
|||||||
i = 0;
|
i = 0;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
// Moves the platform towards the next point
|
||||||
transform.position = Vector2.MoveTowards(transform.position, points[i].position, speed * Time.deltaTime);
|
transform.position = Vector2.MoveTowards(transform.position, points[i].position, speed * Time.deltaTime);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -12,7 +12,7 @@ public class ObjectVisibility : MonoBehaviour
|
|||||||
UpdateVisibility();
|
UpdateVisibility();
|
||||||
}
|
}
|
||||||
|
|
||||||
private void UpdateVisibility()
|
private void UpdateVisibility() // Sets object visible if playing keep away mode
|
||||||
{
|
{
|
||||||
if (GameManager.gameMode == GameManager.GameMode.keepAway)
|
if (GameManager.gameMode == GameManager.GameMode.keepAway)
|
||||||
{
|
{
|
||||||
@@ -7,7 +7,7 @@ public class PlayerJoinCard : MonoBehaviour
|
|||||||
public int playerNumber;
|
public int playerNumber;
|
||||||
public TextMeshProUGUI playerNumberText;
|
public TextMeshProUGUI playerNumberText;
|
||||||
|
|
||||||
void Start()
|
void Start() // Sets player number
|
||||||
{
|
{
|
||||||
playerNumberText.text = playerNumber.ToString();
|
playerNumberText.text = playerNumber.ToString();
|
||||||
}
|
}
|
||||||
@@ -6,7 +6,7 @@ public class RespawnOnTriggerEnter : MonoBehaviour
|
|||||||
public bool spawnPointIsInitialPosition = false;
|
public bool spawnPointIsInitialPosition = false;
|
||||||
public string respawnTag;
|
public string respawnTag;
|
||||||
|
|
||||||
private void Start()
|
private void Start() // Set the spawn point to the initial maps spawn point
|
||||||
{
|
{
|
||||||
if (spawnPointIsInitialPosition)
|
if (spawnPointIsInitialPosition)
|
||||||
{
|
{
|
||||||
@@ -18,7 +18,6 @@ public class RespawnOnTriggerEnter : MonoBehaviour
|
|||||||
{
|
{
|
||||||
if (other.CompareTag(respawnTag))
|
if (other.CompareTag(respawnTag))
|
||||||
{
|
{
|
||||||
//GetComponent<Damageable>().Respawn();
|
|
||||||
if (TryGetComponent(out Damageable damageable))
|
if (TryGetComponent(out Damageable damageable))
|
||||||
{
|
{
|
||||||
damageable.Damage(9999f);
|
damageable.Damage(9999f);
|
||||||
@@ -25,19 +25,10 @@ public class TerribleHealthBarScript : MonoBehaviour
|
|||||||
|
|
||||||
void Start()
|
void Start()
|
||||||
{
|
{
|
||||||
if (player == null)
|
InitializePlayer(player);
|
||||||
{
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
healthScript = player.GetComponent<Damageable>();
|
|
||||||
if (healthScript == null)
|
|
||||||
{
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
Initialize();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void Update()
|
void Update() // Updates each player's health bar to display their current health
|
||||||
{
|
{
|
||||||
if (player == null || healthScript == null)
|
if (player == null || healthScript == null)
|
||||||
{
|
{
|
||||||
@@ -59,6 +50,11 @@ public class TerribleHealthBarScript : MonoBehaviour
|
|||||||
}
|
}
|
||||||
|
|
||||||
public void SetPlayer(GameObject player)
|
public void SetPlayer(GameObject player)
|
||||||
|
{
|
||||||
|
InitializePlayer(player);
|
||||||
|
}
|
||||||
|
|
||||||
|
private void InitializePlayer(GameObject player) // Adds a health bar for each player
|
||||||
{
|
{
|
||||||
this.player = player;
|
this.player = player;
|
||||||
if (this.player == null)
|
if (this.player == null)
|
||||||
@@ -73,7 +69,7 @@ public class TerribleHealthBarScript : MonoBehaviour
|
|||||||
Initialize();
|
Initialize();
|
||||||
}
|
}
|
||||||
|
|
||||||
private void Initialize()
|
private void Initialize() // Sets up the health bars
|
||||||
{
|
{
|
||||||
initialScale = healthVisual.transform.localScale;
|
initialScale = healthVisual.transform.localScale;
|
||||||
initialPosition = healthVisual.transform.position;
|
initialPosition = healthVisual.transform.position;
|
||||||
@@ -7,7 +7,7 @@ public class WinScreen : MonoBehaviour
|
|||||||
public static WinScreen Instance;
|
public static WinScreen Instance;
|
||||||
public List<TextMeshProUGUI> playerTexts;
|
public List<TextMeshProUGUI> playerTexts;
|
||||||
|
|
||||||
private void Awake()
|
private void Awake() // Ensures only one instance of WinScreen exists
|
||||||
{
|
{
|
||||||
if (Instance == null)
|
if (Instance == null)
|
||||||
{
|
{
|
||||||
@@ -19,7 +19,7 @@ public class WinScreen : MonoBehaviour
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public void ShowWinScreen(int player)
|
public void ShowWinScreen(int player) // Triggers the win screen to appear
|
||||||
{
|
{
|
||||||
foreach (TextMeshProUGUI playerText in playerTexts)
|
foreach (TextMeshProUGUI playerText in playerTexts)
|
||||||
{
|
{
|
||||||
@@ -12,7 +12,7 @@ public class MusicManager : MonoBehaviour
|
|||||||
private Dictionary<string, Playlist> sceneToPlaylist = new Dictionary<string, Playlist>();
|
private Dictionary<string, Playlist> sceneToPlaylist = new Dictionary<string, Playlist>();
|
||||||
public GameObject songPrefab;
|
public GameObject songPrefab;
|
||||||
|
|
||||||
private void Awake()
|
private void Awake() // Creates only one MusicManager instance at a time
|
||||||
{
|
{
|
||||||
if (Instance == null)
|
if (Instance == null)
|
||||||
{
|
{
|
||||||
@@ -32,7 +32,7 @@ public class MusicManager : MonoBehaviour
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public void StartPlaylist()
|
public void StartPlaylist() // Starts music playlist for each scene
|
||||||
{
|
{
|
||||||
if (GetActiveSceneNotTitleScreen() == "Player Select") return;
|
if (GetActiveSceneNotTitleScreen() == "Player Select") return;
|
||||||
StopAllCoroutines();
|
StopAllCoroutines();
|
||||||
@@ -51,7 +51,7 @@ public class MusicManager : MonoBehaviour
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public void StartPlaylist(string scene)
|
public void StartPlaylist(string scene) // Sets music for Title Screen
|
||||||
{
|
{
|
||||||
if (GetActiveSceneNotTitleScreen() == "Player Select") return;
|
if (GetActiveSceneNotTitleScreen() == "Player Select") return;
|
||||||
StopAllCoroutines();
|
StopAllCoroutines();
|
||||||
@@ -66,6 +66,7 @@ public class MusicManager : MonoBehaviour
|
|||||||
{
|
{
|
||||||
while (true)
|
while (true)
|
||||||
{
|
{
|
||||||
|
// Shuffles the playlist
|
||||||
List<AudioClip> randomized = new List<AudioClip>(playlist.songs);
|
List<AudioClip> randomized = new List<AudioClip>(playlist.songs);
|
||||||
for (int i = 0; i < randomized.Count; i++)
|
for (int i = 0; i < randomized.Count; i++)
|
||||||
{
|
{
|
||||||
@@ -75,6 +76,7 @@ public class MusicManager : MonoBehaviour
|
|||||||
randomized[randomIndex] = temp;
|
randomized[randomIndex] = temp;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Starts the music in the playlist
|
||||||
foreach (AudioClip song in randomized)
|
foreach (AudioClip song in randomized)
|
||||||
{
|
{
|
||||||
AudioSource songInstance = Instantiate(songPrefab, transform).GetComponent<AudioSource>();
|
AudioSource songInstance = Instantiate(songPrefab, transform).GetComponent<AudioSource>();
|
||||||
@@ -101,7 +103,7 @@ public class MusicManager : MonoBehaviour
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public static string GetActiveSceneNotTitleScreen()
|
public static string GetActiveSceneNotTitleScreen() // Finds the scene name besides Title Screen
|
||||||
{
|
{
|
||||||
for (int sceneIndex = 0; sceneIndex < SceneManager.sceneCount; sceneIndex++)
|
for (int sceneIndex = 0; sceneIndex < SceneManager.sceneCount; sceneIndex++)
|
||||||
{
|
{
|
||||||
|
|||||||
8
Assets/Scripts/Player.meta
Normal file
8
Assets/Scripts/Player.meta
Normal file
@@ -0,0 +1,8 @@
|
|||||||
|
fileFormatVersion: 2
|
||||||
|
guid: c9544c3283a37464f88c711b2bcd2f17
|
||||||
|
folderAsset: yes
|
||||||
|
DefaultImporter:
|
||||||
|
externalObjects: {}
|
||||||
|
userData:
|
||||||
|
assetBundleName:
|
||||||
|
assetBundleVariant:
|
||||||
@@ -5,34 +5,30 @@ public class AnimationPlayer : MonoBehaviour
|
|||||||
{
|
{
|
||||||
public enum AnimationState { Idle, Run, Jump, Walk };
|
public enum AnimationState { Idle, Run, Jump, Walk };
|
||||||
public AnimationState state;
|
public AnimationState state;
|
||||||
|
|
||||||
public bool backwards;
|
public bool backwards;
|
||||||
|
|
||||||
public bool block = false;
|
public bool block = false;
|
||||||
|
|
||||||
public AnimationClip clip;
|
public AnimationClip clip;
|
||||||
|
|
||||||
private Animator animator;
|
private Animator animator;
|
||||||
|
|
||||||
private void Start()
|
private void Start() // Plays the specified animation clip
|
||||||
{
|
{
|
||||||
animator = GetComponent<Animator>();
|
animator = GetComponent<Animator>();
|
||||||
animator.Play(clip.name);
|
animator.Play(clip.name);
|
||||||
}
|
}
|
||||||
|
|
||||||
private void LateUpdate()
|
private void LateUpdate() // Updates the animation state
|
||||||
{
|
{
|
||||||
animator.SetInteger("state", (int)state);
|
animator.SetInteger("state", (int)state);
|
||||||
transform.localScale = new Vector3(Mathf.Sign(backwards ? -1 : 1) * Mathf.Abs(transform.localScale.x), transform.localScale.y, transform.localScale.z);
|
transform.localScale = new Vector3(Mathf.Sign(backwards ? -1 : 1) * Mathf.Abs(transform.localScale.x), transform.localScale.y, transform.localScale.z);
|
||||||
animator.SetBool("block", block);
|
animator.SetBool("block", block);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void SetState(AnimationState state)
|
public void SetState(AnimationState state) // Sets the animation state
|
||||||
{
|
{
|
||||||
this.state = state;
|
this.state = state;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void Punch()
|
public void Punch() // Triggers punch animation
|
||||||
{
|
{
|
||||||
animator.SetTrigger("punch");
|
animator.SetTrigger("punch");
|
||||||
}
|
}
|
||||||
@@ -7,7 +7,7 @@ public class Block : MonoBehaviour
|
|||||||
public bool blocking = false;
|
public bool blocking = false;
|
||||||
private InputActionAsset actions;
|
private InputActionAsset actions;
|
||||||
private float blockPressTime = 0f;
|
private float blockPressTime = 0f;
|
||||||
[SerializeField] private float parryThreshold = 0.2f;
|
[SerializeField] private float parryThreshold = 0.2f; // Time for successful parry
|
||||||
private bool isParrying = false;
|
private bool isParrying = false;
|
||||||
|
|
||||||
private void Start()
|
private void Start()
|
||||||
@@ -15,25 +15,25 @@ public class Block : MonoBehaviour
|
|||||||
actions = GetComponent<PlayerInput>().actions;
|
actions = GetComponent<PlayerInput>().actions;
|
||||||
}
|
}
|
||||||
|
|
||||||
private void Update()
|
private void Update() // Player blocks when "block" is pressed
|
||||||
{
|
{
|
||||||
InputAction blockAction = actions.FindAction("Block");
|
InputAction blockAction = actions.FindAction("Block");
|
||||||
if (blockAction.ReadValue<float>() == 1f)
|
if (blockAction.ReadValue<float>() == 1f)
|
||||||
{
|
{
|
||||||
if (!blocking)
|
if (!blocking)
|
||||||
{
|
{
|
||||||
blockPressTime = Time.time;
|
blockPressTime = Time.time; // Start parry timer
|
||||||
}
|
}
|
||||||
blocking = true;
|
blocking = true;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
if (blocking)
|
if (blocking) // Successful parry if blocked in time
|
||||||
{
|
{
|
||||||
float pressDuration = Time.time - blockPressTime;
|
float pressDuration = Time.time - blockPressTime;
|
||||||
if (pressDuration <= parryThreshold)
|
if (pressDuration <= parryThreshold)
|
||||||
{
|
{
|
||||||
Parry();
|
Parry();
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
@@ -7,16 +7,13 @@ using UnityEngine;
|
|||||||
[RequireComponent(typeof(RespawnOnTriggerEnter))]
|
[RequireComponent(typeof(RespawnOnTriggerEnter))]
|
||||||
public class Damageable : MonoBehaviour
|
public class Damageable : MonoBehaviour
|
||||||
{
|
{
|
||||||
public float force = 50f;
|
public float force = 50f; // Force applied when hit
|
||||||
public float damage = 0f;
|
public float damage = 0f;
|
||||||
public float maxDamage = 1000f;
|
public float maxDamage = 1000f; // Set max health
|
||||||
public int lives = 3;
|
public int lives = 0;
|
||||||
private Animator animator;
|
private Animator animator;
|
||||||
|
|
||||||
public bool damageSelfDebug = false;
|
public bool damageSelfDebug = false;
|
||||||
|
|
||||||
public bool dying = false;
|
public bool dying = false;
|
||||||
|
|
||||||
public event System.Action<GameObject> OnPlayerPunched;
|
public event System.Action<GameObject> OnPlayerPunched;
|
||||||
|
|
||||||
private void Start()
|
private void Start()
|
||||||
@@ -33,38 +30,37 @@ public class Damageable : MonoBehaviour
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private void OnTriggerEnter2D(Collider2D collision)
|
private void OnTriggerEnter2D(Collider2D collision) // Calls Damage method when player is hit
|
||||||
{
|
{
|
||||||
if (collision.gameObject.CompareTag("Punch Hurtbox"))
|
if (collision.gameObject.CompareTag("Punch Hurtbox"))
|
||||||
{
|
{
|
||||||
//print($"{name}: Ouch");
|
|
||||||
Damage(collision.transform.parent.gameObject);
|
Damage(collision.transform.parent.gameObject);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private void Damage(GameObject damageSource)
|
private void Damage(GameObject damageSource) // Damages player
|
||||||
{
|
{
|
||||||
if (dying) return;
|
if (dying) return;
|
||||||
|
|
||||||
float actualForce = damageSource.GetComponent<Damageable>().force;
|
float actualForce = damageSource.GetComponent<Damageable>().force;
|
||||||
Block blockComponent = GetComponent<Block>();
|
Block blockComponent = GetComponent<Block>();
|
||||||
|
|
||||||
GetComponentInChildren<UseItem>().DropItem();
|
GetComponentInChildren<UseItem>().DropItem(); // Drops hat if held
|
||||||
|
|
||||||
if (blockComponent != null && blockComponent.blocking)
|
if (blockComponent != null && blockComponent.blocking)
|
||||||
{
|
{
|
||||||
if (blockComponent.IsParrying())
|
if (blockComponent.IsParrying()) // Player receives damage if punching a parrying player
|
||||||
{
|
{
|
||||||
damageSource.GetComponent<Damageable>().SuccessfulParry(gameObject, actualForce);
|
damageSource.GetComponent<Damageable>().SuccessfulParry(gameObject, actualForce);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
else
|
else // Player does less damage if punching a blocking player
|
||||||
{
|
{
|
||||||
actualForce /= 4;
|
actualForce /= 4;
|
||||||
GetComponent<Rigidbody2D>().AddForce(((transform.position - damageSource.transform.position).normalized + Vector3.up * 2) * actualForce, ForceMode2D.Force);
|
GetComponent<Rigidbody2D>().AddForce(((transform.position - damageSource.transform.position).normalized + Vector3.up * 2) * actualForce, ForceMode2D.Force);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else
|
else // Player does full damage to a non-blocking player
|
||||||
{
|
{
|
||||||
GetComponent<Rigidbody2D>().AddForce(((transform.position - damageSource.transform.position).normalized + Vector3.up * 2) * actualForce * (1 + (damage / maxDamage) * 3), ForceMode2D.Force);
|
GetComponent<Rigidbody2D>().AddForce(((transform.position - damageSource.transform.position).normalized + Vector3.up * 2) * actualForce * (1 + (damage / maxDamage) * 3), ForceMode2D.Force);
|
||||||
}
|
}
|
||||||
@@ -76,7 +72,7 @@ public class Damageable : MonoBehaviour
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public void Damage(float damage)
|
public void Damage(float damage) // Adds damage to player when hit
|
||||||
{
|
{
|
||||||
this.damage += damage;
|
this.damage += damage;
|
||||||
if (damage >= maxDamage)
|
if (damage >= maxDamage)
|
||||||
@@ -96,7 +92,7 @@ public class Damageable : MonoBehaviour
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private void Die()
|
private void Die() // Triggers death animation and sets player to dying state
|
||||||
{
|
{
|
||||||
if (GameManager.Instance != null)
|
if (GameManager.Instance != null)
|
||||||
{
|
{
|
||||||
@@ -106,14 +102,14 @@ public class Damageable : MonoBehaviour
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public void HandleDeath()
|
public void HandleDeath() // Removes player from dying state after respawn
|
||||||
{
|
{
|
||||||
GameManager.Instance.PlayerDied(this);
|
GameManager.Instance.PlayerDied(this);
|
||||||
animator.SetBool("die", false);
|
animator.SetBool("die", false);
|
||||||
dying = false;
|
dying = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void Respawn()
|
public void Respawn() // Respawns player to the spawnPosition and resets damage/health bar
|
||||||
{
|
{
|
||||||
transform.position = GameManager.Instance.spawnPosition;
|
transform.position = GameManager.Instance.spawnPosition;
|
||||||
if (TryGetComponent<Rigidbody2D>(out var rb))
|
if (TryGetComponent<Rigidbody2D>(out var rb))
|
||||||
@@ -1,7 +1,6 @@
|
|||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using UnityEngine;
|
using UnityEngine;
|
||||||
|
|
||||||
// This won scene thing is just duct taped on for the presentation.
|
|
||||||
public class PlayerCameraMovement : MonoBehaviour
|
public class PlayerCameraMovement : MonoBehaviour
|
||||||
{
|
{
|
||||||
private Vector3 start;
|
private Vector3 start;
|
||||||
@@ -10,7 +9,6 @@ public class PlayerCameraMovement : MonoBehaviour
|
|||||||
public float speed;
|
public float speed;
|
||||||
private GameObject playerThatWon;
|
private GameObject playerThatWon;
|
||||||
public float lowerBound;
|
public float lowerBound;
|
||||||
|
|
||||||
public bool winScene = false;
|
public bool winScene = false;
|
||||||
|
|
||||||
private void Start()
|
private void Start()
|
||||||
@@ -20,7 +18,7 @@ public class PlayerCameraMovement : MonoBehaviour
|
|||||||
|
|
||||||
private void Update()
|
private void Update()
|
||||||
{
|
{
|
||||||
if (winScene)
|
if (winScene) // If the game is over, the camera will follow the player that won
|
||||||
{
|
{
|
||||||
if (playerThatWon == null || !playerThatWon.activeInHierarchy)
|
if (playerThatWon == null || !playerThatWon.activeInHierarchy)
|
||||||
{
|
{
|
||||||
@@ -39,6 +37,7 @@ public class PlayerCameraMovement : MonoBehaviour
|
|||||||
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
// Moves the camera to follow the players
|
||||||
List<GameObject> players = GameManager.players;
|
List<GameObject> players = GameManager.players;
|
||||||
if (players.Count == 0) return;
|
if (players.Count == 0) return;
|
||||||
Vector3 playerAverage = Vector3.zero;
|
Vector3 playerAverage = Vector3.zero;
|
||||||
@@ -70,7 +69,7 @@ public class PlayerCameraMovement : MonoBehaviour
|
|||||||
playerThatWon = player;
|
playerThatWon = player;
|
||||||
}
|
}
|
||||||
|
|
||||||
private GameObject FindWinner()
|
private GameObject FindWinner() // Finds the player that won
|
||||||
{
|
{
|
||||||
foreach (GameObject player in GameManager.players)
|
foreach (GameObject player in GameManager.players)
|
||||||
{
|
{
|
||||||
@@ -23,9 +23,8 @@ public class PlayerManager : MonoBehaviour
|
|||||||
GetComponent<PlayerInputManager>().onPlayerLeft += OnPlayerLeft;
|
GetComponent<PlayerInputManager>().onPlayerLeft += OnPlayerLeft;
|
||||||
}
|
}
|
||||||
|
|
||||||
private void OnPlayerJoined(PlayerInput playerInput)
|
private void OnPlayerJoined(PlayerInput playerInput) // Adds a player when they join
|
||||||
{
|
{
|
||||||
//playerInput.transform.SetParent(transform);
|
|
||||||
if (gameStarted)
|
if (gameStarted)
|
||||||
{
|
{
|
||||||
Destroy(playerInput.gameObject);
|
Destroy(playerInput.gameObject);
|
||||||
@@ -41,7 +40,7 @@ public class PlayerManager : MonoBehaviour
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
private void OnPlayerLeft(PlayerInput playerInput)
|
private void OnPlayerLeft(PlayerInput playerInput) // Removes the player if they leave
|
||||||
{
|
{
|
||||||
Destroy(playerInput.gameObject);
|
Destroy(playerInput.gameObject);
|
||||||
GameManager.players.Remove(playerInput.gameObject);
|
GameManager.players.Remove(playerInput.gameObject);
|
||||||
@@ -60,7 +59,7 @@ public class PlayerManager : MonoBehaviour
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public void StartGame()
|
public void StartGame() // Allows game to start after a player has joined
|
||||||
{
|
{
|
||||||
if (GameManager.players.Count == 0)
|
if (GameManager.players.Count == 0)
|
||||||
{
|
{
|
||||||
@@ -70,7 +69,7 @@ public class PlayerManager : MonoBehaviour
|
|||||||
HubManager.Instance.LoadScene(GameManager.map);
|
HubManager.Instance.LoadScene(GameManager.map);
|
||||||
}
|
}
|
||||||
|
|
||||||
private void Colorize(int index)
|
private void Colorize(int index) // Pairs each player with a unique color
|
||||||
{
|
{
|
||||||
GameObject player = GameManager.players[index];
|
GameObject player = GameManager.players[index];
|
||||||
Color color = playerColors[(GameManager.players.Count - 1) % playerColors.Count];
|
Color color = playerColors[(GameManager.players.Count - 1) % playerColors.Count];
|
||||||
@@ -81,7 +80,7 @@ public class PlayerManager : MonoBehaviour
|
|||||||
ApplyColor(cards[GameManager.players.IndexOf(player)].playerPreview, color);
|
ApplyColor(cards[GameManager.players.IndexOf(player)].playerPreview, color);
|
||||||
}
|
}
|
||||||
|
|
||||||
private void ApplyColor(GameObject obj, Color color)
|
private void ApplyColor(GameObject obj, Color color) // Applies a color to each player
|
||||||
{
|
{
|
||||||
if (obj.TryGetComponent<SpriteRenderer>(out _))
|
if (obj.TryGetComponent<SpriteRenderer>(out _))
|
||||||
{
|
{
|
||||||
@@ -18,20 +18,20 @@ public class PlayerMovement : MonoBehaviour
|
|||||||
|
|
||||||
[Header("Movement")]
|
[Header("Movement")]
|
||||||
public float walkSpeed;
|
public float walkSpeed;
|
||||||
public float walkSpeedFactor = 1f;
|
public float walkSpeedFactor = 1f; // Sets walk speed
|
||||||
public float maxSpeed = 5f;
|
public float maxSpeed = 5f; // Sets max speed
|
||||||
public float maxSpeedOverride;
|
public float maxSpeedOverride;
|
||||||
public float slowdownMultiplier = 10f;
|
public float slowdownMultiplier = 10f; // Sets slow walk speed
|
||||||
public float virtualAxisX;
|
public float virtualAxisX;
|
||||||
public float virtualButtonJump;
|
public float virtualButtonJump;
|
||||||
public float virtualButtonJumpLastFrame;
|
public float virtualButtonJumpLastFrame;
|
||||||
public float turnaroundMultiplier = 2;
|
public float turnaroundMultiplier = 2; // Sets speed when turning around
|
||||||
public float walkSmooth;
|
public float walkSmooth;
|
||||||
public float secondsToFullSpeed;
|
public float secondsToFullSpeed;
|
||||||
public float jumpSpeed;
|
public float jumpSpeed;
|
||||||
public float coyoteTime;
|
public float coyoteTime;
|
||||||
public float jumpLenience;
|
public float jumpLenience;
|
||||||
public float timeUnableToBeDeclaredNotJumping = 0.1f;
|
public float timeUnableToBeDeclaredNotJumping = 0.1f; // Jump threshold
|
||||||
public float groundCheckDistance;
|
public float groundCheckDistance;
|
||||||
|
|
||||||
private Rigidbody2D body;
|
private Rigidbody2D body;
|
||||||
@@ -42,19 +42,15 @@ public class PlayerMovement : MonoBehaviour
|
|||||||
private Damageable damageable;
|
private Damageable damageable;
|
||||||
|
|
||||||
private bool jumpInputStillValid = false;
|
private bool jumpInputStillValid = false;
|
||||||
private float lastTimeJumpPressed;
|
|
||||||
|
|
||||||
private bool canBeDeclaredNotJumping = true;
|
private bool canBeDeclaredNotJumping = true;
|
||||||
|
|
||||||
private bool jumpPhysics;
|
private bool jumpPhysics;
|
||||||
|
|
||||||
private bool jumping;
|
private bool jumping;
|
||||||
|
private float lastTimeJumpPressed;
|
||||||
private float lastTimeOnGround;
|
private float lastTimeOnGround;
|
||||||
|
|
||||||
private Vector3 positionLastFrame;
|
private Vector3 positionLastFrame;
|
||||||
|
|
||||||
void Start()
|
void Start() // Sets up player components
|
||||||
{
|
{
|
||||||
maxSpeedOverride = maxSpeed;
|
maxSpeedOverride = maxSpeed;
|
||||||
GetComponent<RespawnOnTriggerEnter>().spawnPoint = transform.position;
|
GetComponent<RespawnOnTriggerEnter>().spawnPoint = transform.position;
|
||||||
@@ -69,10 +65,10 @@ public class PlayerMovement : MonoBehaviour
|
|||||||
playerText.text = input.playerIndex.ToString();
|
playerText.text = input.playerIndex.ToString();
|
||||||
}
|
}
|
||||||
|
|
||||||
private void Update()
|
private void Update() // Updates player movement
|
||||||
{
|
{
|
||||||
if (GameManager.Instance != null && GameManager.Instance.gameOver) maxSpeed = 1f;
|
if (GameManager.Instance != null && GameManager.Instance.gameOver) maxSpeed = 1f;
|
||||||
if (damageable.dying/* || (GameManager.Instance != null && GameManager.Instance.gameOver)*/) return;
|
if (damageable.dying) return;
|
||||||
|
|
||||||
Jump();
|
Jump();
|
||||||
|
|
||||||
@@ -88,12 +84,12 @@ public class PlayerMovement : MonoBehaviour
|
|||||||
Land();
|
Land();
|
||||||
}
|
}
|
||||||
|
|
||||||
private void LateUpdate()
|
private void LateUpdate()
|
||||||
{
|
{
|
||||||
Animate();
|
Animate();
|
||||||
}
|
}
|
||||||
|
|
||||||
private void Animate()
|
private void Animate() // Sets player animation
|
||||||
{
|
{
|
||||||
if (!IsPhysicallyGrounded())
|
if (!IsPhysicallyGrounded())
|
||||||
animationPlayer.SetState(AnimationPlayer.AnimationState.Jump);
|
animationPlayer.SetState(AnimationPlayer.AnimationState.Jump);
|
||||||
@@ -111,7 +107,7 @@ public class PlayerMovement : MonoBehaviour
|
|||||||
animationPlayer.backwards = false;
|
animationPlayer.backwards = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
private void Land()
|
private void Land() // Stops jumping when player lands
|
||||||
{
|
{
|
||||||
if (body.linearVelocity.y >= 0f) return;
|
if (body.linearVelocity.y >= 0f) return;
|
||||||
|
|
||||||
@@ -124,10 +120,8 @@ public class PlayerMovement : MonoBehaviour
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private void Jump()
|
private void Jump() // Player jumps when 'jump' is pressed
|
||||||
{
|
{
|
||||||
//if (!punch.cancelable) return;
|
|
||||||
|
|
||||||
if (virtualButtonJumpLastFrame == 1f)
|
if (virtualButtonJumpLastFrame == 1f)
|
||||||
{
|
{
|
||||||
jumpInputStillValid = true;
|
jumpInputStillValid = true;
|
||||||
@@ -145,7 +139,7 @@ public class PlayerMovement : MonoBehaviour
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private void JumpPhysics()
|
private void JumpPhysics() // Applies jump physics
|
||||||
{
|
{
|
||||||
if (jumpPhysics)
|
if (jumpPhysics)
|
||||||
{
|
{
|
||||||
@@ -165,14 +159,14 @@ public class PlayerMovement : MonoBehaviour
|
|||||||
body.AddForce(Vector2.down * jumpSpeed);
|
body.AddForce(Vector2.down * jumpSpeed);
|
||||||
}
|
}
|
||||||
|
|
||||||
private IEnumerator NotJumpingDelay()
|
private IEnumerator NotJumpingDelay() // Sets jump threshold
|
||||||
{
|
{
|
||||||
canBeDeclaredNotJumping = false;
|
canBeDeclaredNotJumping = false;
|
||||||
yield return new WaitUntil(() => !IsBasicallyGrounded());
|
yield return new WaitUntil(() => !IsBasicallyGrounded());
|
||||||
canBeDeclaredNotJumping = true;
|
canBeDeclaredNotJumping = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
private void HorizontalMovement()
|
private void HorizontalMovement() // Sets player horizontal movement
|
||||||
{
|
{
|
||||||
float temporaryMax = IsPhysicallyGrounded() ? maxSpeedOverride : Mathf.Infinity;
|
float temporaryMax = IsPhysicallyGrounded() ? maxSpeedOverride : Mathf.Infinity;
|
||||||
float temporarySlowdown = IsPhysicallyGrounded() ? slowdownMultiplier : 1;
|
float temporarySlowdown = IsPhysicallyGrounded() ? slowdownMultiplier : 1;
|
||||||
@@ -184,7 +178,6 @@ public class PlayerMovement : MonoBehaviour
|
|||||||
|
|
||||||
if (Mathf.Abs(body.linearVelocityX) >= temporaryMax)
|
if (Mathf.Abs(body.linearVelocityX) >= temporaryMax)
|
||||||
{
|
{
|
||||||
//body.linearVelocity = new Vector2(Mathf.Sign(body.linearVelocityX) * temporaryMax, body.linearVelocity.y);
|
|
||||||
body.AddForce(new Vector2(-Mathf.Sign(body.linearVelocityX) * (Mathf.Abs(body.linearVelocityX) - temporaryMax) * temporarySlowdown, 0));
|
body.AddForce(new Vector2(-Mathf.Sign(body.linearVelocityX) * (Mathf.Abs(body.linearVelocityX) - temporaryMax) * temporarySlowdown, 0));
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -201,7 +194,7 @@ public class PlayerMovement : MonoBehaviour
|
|||||||
positionLastFrame = transform.position;
|
positionLastFrame = transform.position;
|
||||||
}
|
}
|
||||||
|
|
||||||
private void UpdateVirtualAxis()
|
private void UpdateVirtualAxis() // Updates virtual axis
|
||||||
{
|
{
|
||||||
virtualButtonJump = input.actions.FindAction("Action").ReadValue<float>();
|
virtualButtonJump = input.actions.FindAction("Action").ReadValue<float>();
|
||||||
virtualButtonJumpLastFrame = input.actions.FindAction("Action").WasPressedThisFrame() ? 1 : 0;
|
virtualButtonJumpLastFrame = input.actions.FindAction("Action").WasPressedThisFrame() ? 1 : 0;
|
||||||
@@ -210,7 +203,7 @@ public class PlayerMovement : MonoBehaviour
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
public bool IsBasicallyGrounded()
|
public bool IsBasicallyGrounded() // Checks if player is on land within a threshold
|
||||||
{
|
{
|
||||||
if (IsPhysicallyGrounded())
|
if (IsPhysicallyGrounded())
|
||||||
{
|
{
|
||||||
@@ -225,7 +218,7 @@ public class PlayerMovement : MonoBehaviour
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
public bool IsPhysicallyGrounded()
|
public bool IsPhysicallyGrounded() // Checks if player is on land
|
||||||
{
|
{
|
||||||
RaycastHit2D leftCheck = Physics2D.Raycast(GetPointInBoxCollider(collide, -1, -1), Vector2.down, groundCheckDistance, ground);
|
RaycastHit2D leftCheck = Physics2D.Raycast(GetPointInBoxCollider(collide, -1, -1), Vector2.down, groundCheckDistance, ground);
|
||||||
RaycastHit2D rightCheck = Physics2D.Raycast(GetPointInBoxCollider(collide, 1, -1), Vector2.down, groundCheckDistance, ground);
|
RaycastHit2D rightCheck = Physics2D.Raycast(GetPointInBoxCollider(collide, 1, -1), Vector2.down, groundCheckDistance, ground);
|
||||||
@@ -239,7 +232,7 @@ public class PlayerMovement : MonoBehaviour
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
public Vector2 GetPointInBoxCollider(BoxCollider2D boxCollider2D, float horizontal, float vertical)
|
public Vector2 GetPointInBoxCollider(BoxCollider2D boxCollider2D, float horizontal, float vertical)
|
||||||
{
|
{
|
||||||
return new Vector2
|
return new Vector2
|
||||||
(
|
(
|
||||||
@@ -248,7 +241,7 @@ public class PlayerMovement : MonoBehaviour
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void StopVelocity()
|
public void StopVelocity() // Stops inertia when landed
|
||||||
{
|
{
|
||||||
if (IsPhysicallyGrounded()) body.linearVelocity = Vector2.zero;
|
if (IsPhysicallyGrounded()) body.linearVelocity = Vector2.zero;
|
||||||
}
|
}
|
||||||
@@ -16,7 +16,7 @@ public class Punch : MonoBehaviour
|
|||||||
actions = GetComponent<PlayerInput>().actions;
|
actions = GetComponent<PlayerInput>().actions;
|
||||||
}
|
}
|
||||||
|
|
||||||
private void Update()
|
private void Update() // Executes punch when 'punch' is pressed
|
||||||
{
|
{
|
||||||
if (actions.FindAction("Punch").WasPressedThisFrame())
|
if (actions.FindAction("Punch").WasPressedThisFrame())
|
||||||
{
|
{
|
||||||
@@ -25,12 +25,11 @@ public class Punch : MonoBehaviour
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private void ExecutePunch()
|
private void ExecutePunch() // Triggers punch animation
|
||||||
{
|
{
|
||||||
GetComponent<AnimationPlayer>().Punch();
|
GetComponent<AnimationPlayer>().Punch();
|
||||||
DisableCancellation();
|
DisableCancellation();
|
||||||
GetComponent<PlayerMovement>().maxSpeedOverride = 1f;
|
GetComponent<PlayerMovement>().maxSpeedOverride = 1f; // Slows player down when punching
|
||||||
//OnPlayerPunched?.Invoke(gameObject);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public void EnableHurtbox()
|
public void EnableHurtbox()
|
||||||
@@ -53,7 +52,7 @@ public class Punch : MonoBehaviour
|
|||||||
cancelable = true;
|
cancelable = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void ReturnToMaxSpeed()
|
public void ReturnToMaxSpeed() // Resets player speed after punch
|
||||||
{
|
{
|
||||||
GetComponent<PlayerMovement>().maxSpeedOverride = GetComponent<PlayerMovement>().maxSpeed;
|
GetComponent<PlayerMovement>().maxSpeedOverride = GetComponent<PlayerMovement>().maxSpeed;
|
||||||
}
|
}
|
||||||
@@ -3,25 +3,15 @@ using UnityEngine;
|
|||||||
public class TeleportPlatform : MonoBehaviour
|
public class TeleportPlatform : MonoBehaviour
|
||||||
{
|
{
|
||||||
public Vector2 teleportPoint;
|
public Vector2 teleportPoint;
|
||||||
//public bool teleportPosition = false;
|
|
||||||
public string teleportTag;
|
public string teleportTag;
|
||||||
public string playerTag = "Player";
|
public string playerTag = "Player";
|
||||||
|
|
||||||
|
|
||||||
public bool isPlatform = true;
|
public bool isPlatform = true;
|
||||||
|
|
||||||
//private void Start()
|
|
||||||
//{
|
|
||||||
//if (teleportPosition)
|
|
||||||
//{
|
|
||||||
//teleportPoint = transform.position;
|
|
||||||
//}
|
|
||||||
//}
|
|
||||||
|
|
||||||
private void OnTriggerEnter2D(Collider2D collision)
|
private void OnTriggerEnter2D(Collider2D collision)
|
||||||
{
|
{
|
||||||
if (!isPlatform)
|
if (!isPlatform)
|
||||||
{
|
{
|
||||||
|
// Teleports the platform
|
||||||
if (collision.CompareTag(teleportTag))
|
if (collision.CompareTag(teleportTag))
|
||||||
{
|
{
|
||||||
transform.position = teleportPoint;
|
transform.position = teleportPoint;
|
||||||
@@ -33,6 +23,7 @@ public class TeleportPlatform : MonoBehaviour
|
|||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
|
// Teleports the player
|
||||||
if (collision.CompareTag(playerTag))
|
if (collision.CompareTag(playerTag))
|
||||||
{
|
{
|
||||||
collision.transform.position = teleportPoint;
|
collision.transform.position = teleportPoint;
|
||||||
@@ -12,16 +12,18 @@ public class UseItem : MonoBehaviour
|
|||||||
{
|
{
|
||||||
if (isHoldingItem)
|
if (isHoldingItem)
|
||||||
{
|
{
|
||||||
|
// Keeps hat on the player's head
|
||||||
heldItem.transform.position = transform.position + Vector3.up;
|
heldItem.transform.position = transform.position + Vector3.up;
|
||||||
if (GameManager.gameMode == GameManager.GameMode.keepAway)
|
if (GameManager.gameMode == GameManager.GameMode.keepAway)
|
||||||
{
|
{
|
||||||
|
// Adds time to the player's leaderboard standing
|
||||||
holdTime += Time.deltaTime;
|
holdTime += Time.deltaTime;
|
||||||
GameManager.Instance.UpdatePlayerHoldTime(gameObject, holdTime);
|
GameManager.Instance.UpdatePlayerHoldTime(gameObject, holdTime);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private void OnCollisionEnter2D(Collision2D collision)
|
private void OnCollisionEnter2D(Collision2D collision) // Player automatically picks up hat when touching it
|
||||||
{
|
{
|
||||||
if (collision.gameObject.CompareTag("Hat") && !isHoldingItem)
|
if (collision.gameObject.CompareTag("Hat") && !isHoldingItem)
|
||||||
{
|
{
|
||||||
@@ -29,7 +31,7 @@ public class UseItem : MonoBehaviour
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private void PickUpItem(GameObject item)
|
private void PickUpItem(GameObject item) // Player picks up hat and starts hold counter
|
||||||
{
|
{
|
||||||
heldItem = item;
|
heldItem = item;
|
||||||
isHoldingItem = true;
|
isHoldingItem = true;
|
||||||
@@ -43,7 +45,7 @@ public class UseItem : MonoBehaviour
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public void DropItem()
|
public void DropItem() // Player drops hat when hit
|
||||||
{
|
{
|
||||||
if (isHoldingItem)
|
if (isHoldingItem)
|
||||||
{
|
{
|
||||||
@@ -58,22 +60,4 @@ public class UseItem : MonoBehaviour
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private void OnEnable()
|
|
||||||
{
|
|
||||||
//Punch.OnPlayerPunched += HandlePlayerPunched;
|
|
||||||
}
|
|
||||||
|
|
||||||
private void OnDisable()
|
|
||||||
{
|
|
||||||
//Punch.OnPlayerPunched -= HandlePlayerPunched;
|
|
||||||
}
|
|
||||||
/*
|
|
||||||
private void HandlePlayerPunched(GameObject punchedPlayer)
|
|
||||||
{
|
|
||||||
if (punchedPlayer == gameObject)
|
|
||||||
{
|
|
||||||
DropItem();
|
|
||||||
}
|
|
||||||
}*/
|
|
||||||
}
|
}
|
||||||
@@ -1,7 +0,0 @@
|
|||||||
using System.Collections;
|
|
||||||
using UnityEngine;
|
|
||||||
|
|
||||||
public class SmoothToTarget : MonoBehaviour
|
|
||||||
{
|
|
||||||
|
|
||||||
}
|
|
||||||
@@ -1,2 +0,0 @@
|
|||||||
fileFormatVersion: 2
|
|
||||||
guid: 617fdbd52246c4352be58c24aef4fd55
|
|
||||||
Reference in New Issue
Block a user