added comments and organized project files
This commit is contained in:
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;
|
||||
|
||||
private void Awake()
|
||||
private void Awake() // Ensures only one instance of PlayerCardCreator exists
|
||||
{
|
||||
if (Instance == null) Instance = this;
|
||||
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);
|
||||
return card.GetComponent<PlayerJoinCard>();
|
||||
@@ -3,7 +3,7 @@ using UnityEngine.EventSystems;
|
||||
|
||||
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))
|
||||
{
|
||||
@@ -3,8 +3,8 @@ using UnityEngine;
|
||||
|
||||
public class FallPlatform : MonoBehaviour
|
||||
{
|
||||
public float fallDelay = 2f;
|
||||
public float resetDelay = 4f;
|
||||
public float fallDelay = 2f; // Delay before the platform falls
|
||||
public float resetDelay = 4f; // Delay before the platform resets
|
||||
|
||||
bool falling;
|
||||
Rigidbody2D rb;
|
||||
@@ -15,7 +15,7 @@ public class FallPlatform : MonoBehaviour
|
||||
defposition = transform.parent.position;
|
||||
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 _)))
|
||||
{
|
||||
@@ -23,7 +23,7 @@ public class FallPlatform : MonoBehaviour
|
||||
}
|
||||
}
|
||||
|
||||
private IEnumerator FallAfterDelay()
|
||||
private IEnumerator FallAfterDelay() // Sets platform to fall and respawn
|
||||
{
|
||||
falling = true;
|
||||
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
|
||||
// Use transform.parent to get the object it's attatched to
|
||||
private void Respawn()
|
||||
private void Respawn() // Resets the platform position
|
||||
{
|
||||
falling = false;
|
||||
rb.bodyType = RigidbodyType2D.Static;
|
||||
@@ -6,7 +6,6 @@ using UnityEngine.InputSystem;
|
||||
public class GameManager : MonoBehaviour
|
||||
{
|
||||
public static GameManager Instance { get; private set; }
|
||||
public int maxLives = 3;
|
||||
public float time = 180f;
|
||||
public delegate void GameEvent();
|
||||
public event GameEvent StartGameEvent;
|
||||
@@ -14,14 +13,22 @@ public class GameManager : MonoBehaviour
|
||||
public static List<GameObject> players = new List<GameObject>();
|
||||
public static List<Color> playerColors = new List<Color>();
|
||||
public float offset = 1f;
|
||||
|
||||
public static bool music = true;
|
||||
|
||||
public bool gameOver = false;
|
||||
public GameTimer gameTimer;
|
||||
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)
|
||||
{
|
||||
@@ -33,20 +40,20 @@ public class GameManager : MonoBehaviour
|
||||
}
|
||||
}
|
||||
|
||||
private void Start()
|
||||
private void Start() // Starts the game and music
|
||||
{
|
||||
MusicManager.Instance.StartPlaylist();
|
||||
StartGame();
|
||||
}
|
||||
|
||||
public void StartGame()
|
||||
public void StartGame() // Sets up the proper gamemode
|
||||
{
|
||||
GameManager.playerHoldTimes.Clear();
|
||||
if (GameManager.players.Count == 0) return;
|
||||
|
||||
StartGameEvent?.Invoke();
|
||||
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)
|
||||
{
|
||||
@@ -54,7 +61,7 @@ public class GameManager : MonoBehaviour
|
||||
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.StartTimer();
|
||||
@@ -64,7 +71,7 @@ public class GameManager : MonoBehaviour
|
||||
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)
|
||||
{
|
||||
@@ -73,21 +80,9 @@ public class GameManager : MonoBehaviour
|
||||
}
|
||||
}
|
||||
|
||||
public enum GameMode
|
||||
public void PlayerDied(Damageable player) // Handles player deaths for the respective gamemode
|
||||
{
|
||||
freeForAll,
|
||||
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)
|
||||
if (gameMode == GameMode.freeForAll) // Respawns player if they have lives left
|
||||
{
|
||||
player.lives--;
|
||||
if (player.lives <= 0 && !gameOver)
|
||||
@@ -95,7 +90,7 @@ public class GameManager : MonoBehaviour
|
||||
player.gameObject.SetActive(false);
|
||||
if (AlivePlayers().Count <= 1)
|
||||
{
|
||||
GameOver();
|
||||
GameOver(); // Winner is called when only one player is left
|
||||
}
|
||||
}
|
||||
else
|
||||
@@ -103,7 +98,7 @@ public class GameManager : MonoBehaviour
|
||||
RespawnPlayer(player.gameObject);
|
||||
}
|
||||
}
|
||||
if (gameMode == GameMode.keepAway)
|
||||
if (gameMode == GameMode.keepAway) // Always respawns player regardless of lives
|
||||
{
|
||||
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>();
|
||||
if (respawnScript != null)
|
||||
@@ -124,18 +119,19 @@ public class GameManager : MonoBehaviour
|
||||
}
|
||||
}
|
||||
|
||||
public void GameOver()
|
||||
public void GameOver() // Ends game and displays winner
|
||||
{
|
||||
gameOver = true;
|
||||
EndGameEvent?.Invoke();
|
||||
if (gameMode == GameMode.freeForAll)
|
||||
if (gameMode == GameMode.freeForAll) // Last player alive wins
|
||||
{
|
||||
print(AlivePlayers()[0].name + " is the winner");
|
||||
FindFirstObjectByType<PlayerCameraMovement>().WinScene(AlivePlayers()[0]);
|
||||
WinScreen.Instance.ShowWinScreen(players.IndexOf(AlivePlayers()[0]) + 1);
|
||||
GameObject winner = AlivePlayers()[0];
|
||||
print(winner.name + " is the winner");
|
||||
FindFirstObjectByType<PlayerCameraMovement>().WinScene(winner);
|
||||
WinScreen.Instance.ShowWinScreen(players.IndexOf(winner) + 1);
|
||||
FindFirstObjectByType<LifeDisplayManager>().HideLifeDisplay();
|
||||
}
|
||||
if (gameMode == GameMode.keepAway)
|
||||
if (gameMode == GameMode.keepAway) // Player with the most time holding the hat wins
|
||||
{
|
||||
GameObject winner = null;
|
||||
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();
|
||||
|
||||
@@ -169,7 +165,7 @@ public class GameManager : MonoBehaviour
|
||||
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))
|
||||
{
|
||||
@@ -18,7 +18,7 @@ public class GameTimer : MonoBehaviour
|
||||
UpdateTimerDisplay();
|
||||
}
|
||||
|
||||
private void Update()
|
||||
private void Update() // Updates the timer to show the time remaining
|
||||
{
|
||||
if (timerRunning)
|
||||
{
|
||||
@@ -35,7 +35,7 @@ public class GameTimer : MonoBehaviour
|
||||
}
|
||||
}
|
||||
|
||||
public void StartTimer()
|
||||
public void StartTimer() // Starts the timer
|
||||
{
|
||||
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 seconds = Mathf.FloorToInt(timeRemaining % 60);
|
||||
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();
|
||||
}
|
||||
@@ -2,7 +2,7 @@ using UnityEngine;
|
||||
|
||||
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"))
|
||||
{
|
||||
@@ -18,7 +18,7 @@ public class HealthBarManager : MonoBehaviour
|
||||
GameManager.Instance.EndGameEvent -= OnGameEnd;
|
||||
}
|
||||
|
||||
void Update()
|
||||
void Update() // Updates position of health bars to follow each player
|
||||
{
|
||||
foreach (var kvp in playerHealthBars)
|
||||
{
|
||||
@@ -26,12 +26,11 @@ public class HealthBarManager : MonoBehaviour
|
||||
if (player == null) continue;
|
||||
|
||||
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);
|
||||
}
|
||||
}
|
||||
|
||||
private void OnGameStart()
|
||||
private void OnGameStart() // Creates health bars for each player
|
||||
{
|
||||
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)
|
||||
{
|
||||
@@ -6,7 +6,7 @@ public class InfiniteScroll : MonoBehaviour
|
||||
public float start;
|
||||
public float end;
|
||||
|
||||
private void Update()
|
||||
private void Update() // Moves the background
|
||||
{
|
||||
if (transform.position.x > end)
|
||||
{
|
||||
@@ -8,11 +8,11 @@ public class LeaderboardManager : MonoBehaviour
|
||||
|
||||
[SerializeField] private GameObject playersParent;
|
||||
[SerializeField] private GameObject playerPrefab;
|
||||
[SerializeField] private GameObject lifePrefab;
|
||||
[SerializeField] private GameObject leaderboardIconPrefab;
|
||||
|
||||
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)
|
||||
{
|
||||
@@ -29,36 +29,28 @@ public class LeaderboardManager : MonoBehaviour
|
||||
InitializeLeaderboard();
|
||||
}
|
||||
|
||||
private void InitializeLeaderboard()
|
||||
private void InitializeLeaderboard() // Creates the leaderboard icons for each player
|
||||
{
|
||||
foreach (GameObject player in GameManager.players)
|
||||
{
|
||||
Transform parent = Instantiate(playerPrefab, playersParent.transform).transform;
|
||||
GameObject life = Instantiate(lifePrefab, parent);
|
||||
life.GetComponentInChildren<Image>().color = GameManager.playerColors[GameManager.players.IndexOf(player)];
|
||||
GameObject leaderboardIcon = Instantiate(leaderboardIconPrefab, parent);
|
||||
leaderboardIcon.GetComponentInChildren<Image>().color = GameManager.playerColors[GameManager.players.IndexOf(player)];
|
||||
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);
|
||||
sortedList.Sort((pair1, pair2) => pair2.Value.CompareTo(pair1.Value));
|
||||
|
||||
foreach (var player in sortedList)
|
||||
{
|
||||
Debug.Log(player.Key.name + " : " + player.Value);
|
||||
}
|
||||
// Less fancy sorting system
|
||||
|
||||
foreach (var player in sortedList)
|
||||
{
|
||||
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 playerPrefab;
|
||||
public GameObject lifePrefab;
|
||||
|
||||
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)
|
||||
{
|
||||
@@ -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)
|
||||
{
|
||||
@@ -40,7 +39,7 @@ public class LifeDisplayManager : MonoBehaviour
|
||||
}
|
||||
}
|
||||
|
||||
public void HideLifeDisplay()
|
||||
public void HideLifeDisplay() // Hides life display
|
||||
{
|
||||
players.SetActive(false);
|
||||
}
|
||||
@@ -10,7 +10,7 @@ public class MapSelect : MonoBehaviour
|
||||
maps = GetComponent<ToggleGroup>();
|
||||
}
|
||||
|
||||
void Update()
|
||||
void Update() // Sets the map based on the selected toggle
|
||||
{
|
||||
Toggle toggle = maps.GetFirstActiveToggle();
|
||||
GameManager.map = toggle.name;
|
||||
@@ -10,7 +10,7 @@ public class ModeSelect : MonoBehaviour
|
||||
maps = GetComponent<ToggleGroup>();
|
||||
}
|
||||
|
||||
void Update()
|
||||
void Update() // Updates the game mode based on the selected toggle
|
||||
{
|
||||
Toggle toggle = maps.GetFirstActiveToggle();
|
||||
if (toggle.name == "Free-For-All")
|
||||
@@ -6,16 +6,16 @@ public class MovingPlatform : MonoBehaviour
|
||||
public int startPoint;
|
||||
public Transform[] points;
|
||||
public float speed;
|
||||
|
||||
private int i;
|
||||
|
||||
void Start()
|
||||
void Start() // Sets the initial position of the platform
|
||||
{
|
||||
transform.position = points[startPoint].position;
|
||||
}
|
||||
|
||||
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)
|
||||
{
|
||||
i++;
|
||||
@@ -24,7 +24,7 @@ public class MovingPlatform : MonoBehaviour
|
||||
i = 0;
|
||||
}
|
||||
}
|
||||
|
||||
// Moves the platform towards the next point
|
||||
transform.position = Vector2.MoveTowards(transform.position, points[i].position, speed * Time.deltaTime);
|
||||
}
|
||||
}
|
||||
@@ -12,7 +12,7 @@ public class ObjectVisibility : MonoBehaviour
|
||||
UpdateVisibility();
|
||||
}
|
||||
|
||||
private void UpdateVisibility()
|
||||
private void UpdateVisibility() // Sets object visible if playing keep away mode
|
||||
{
|
||||
if (GameManager.gameMode == GameManager.GameMode.keepAway)
|
||||
{
|
||||
@@ -7,7 +7,7 @@ public class PlayerJoinCard : MonoBehaviour
|
||||
public int playerNumber;
|
||||
public TextMeshProUGUI playerNumberText;
|
||||
|
||||
void Start()
|
||||
void Start() // Sets player number
|
||||
{
|
||||
playerNumberText.text = playerNumber.ToString();
|
||||
}
|
||||
@@ -6,7 +6,7 @@ public class RespawnOnTriggerEnter : MonoBehaviour
|
||||
public bool spawnPointIsInitialPosition = false;
|
||||
public string respawnTag;
|
||||
|
||||
private void Start()
|
||||
private void Start() // Set the spawn point to the initial maps spawn point
|
||||
{
|
||||
if (spawnPointIsInitialPosition)
|
||||
{
|
||||
@@ -18,7 +18,6 @@ public class RespawnOnTriggerEnter : MonoBehaviour
|
||||
{
|
||||
if (other.CompareTag(respawnTag))
|
||||
{
|
||||
//GetComponent<Damageable>().Respawn();
|
||||
if (TryGetComponent(out Damageable damageable))
|
||||
{
|
||||
damageable.Damage(9999f);
|
||||
@@ -25,19 +25,10 @@ public class TerribleHealthBarScript : MonoBehaviour
|
||||
|
||||
void Start()
|
||||
{
|
||||
if (player == null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
healthScript = player.GetComponent<Damageable>();
|
||||
if (healthScript == null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
Initialize();
|
||||
InitializePlayer(player);
|
||||
}
|
||||
|
||||
void Update()
|
||||
void Update() // Updates each player's health bar to display their current health
|
||||
{
|
||||
if (player == null || healthScript == null)
|
||||
{
|
||||
@@ -59,6 +50,11 @@ public class TerribleHealthBarScript : MonoBehaviour
|
||||
}
|
||||
|
||||
public void SetPlayer(GameObject player)
|
||||
{
|
||||
InitializePlayer(player);
|
||||
}
|
||||
|
||||
private void InitializePlayer(GameObject player) // Adds a health bar for each player
|
||||
{
|
||||
this.player = player;
|
||||
if (this.player == null)
|
||||
@@ -73,7 +69,7 @@ public class TerribleHealthBarScript : MonoBehaviour
|
||||
Initialize();
|
||||
}
|
||||
|
||||
private void Initialize()
|
||||
private void Initialize() // Sets up the health bars
|
||||
{
|
||||
initialScale = healthVisual.transform.localScale;
|
||||
initialPosition = healthVisual.transform.position;
|
||||
@@ -7,7 +7,7 @@ public class WinScreen : MonoBehaviour
|
||||
public static WinScreen Instance;
|
||||
public List<TextMeshProUGUI> playerTexts;
|
||||
|
||||
private void Awake()
|
||||
private void Awake() // Ensures only one instance of WinScreen exists
|
||||
{
|
||||
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)
|
||||
{
|
||||
@@ -12,7 +12,7 @@ public class MusicManager : MonoBehaviour
|
||||
private Dictionary<string, Playlist> sceneToPlaylist = new Dictionary<string, Playlist>();
|
||||
public GameObject songPrefab;
|
||||
|
||||
private void Awake()
|
||||
private void Awake() // Creates only one MusicManager instance at a time
|
||||
{
|
||||
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;
|
||||
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;
|
||||
StopAllCoroutines();
|
||||
@@ -66,6 +66,7 @@ public class MusicManager : MonoBehaviour
|
||||
{
|
||||
while (true)
|
||||
{
|
||||
// Shuffles the playlist
|
||||
List<AudioClip> randomized = new List<AudioClip>(playlist.songs);
|
||||
for (int i = 0; i < randomized.Count; i++)
|
||||
{
|
||||
@@ -75,6 +76,7 @@ public class MusicManager : MonoBehaviour
|
||||
randomized[randomIndex] = temp;
|
||||
}
|
||||
|
||||
// Starts the music in the playlist
|
||||
foreach (AudioClip song in randomized)
|
||||
{
|
||||
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++)
|
||||
{
|
||||
|
||||
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 AnimationState state;
|
||||
|
||||
public bool backwards;
|
||||
|
||||
public bool block = false;
|
||||
|
||||
public AnimationClip clip;
|
||||
|
||||
private Animator animator;
|
||||
|
||||
private void Start()
|
||||
private void Start() // Plays the specified animation clip
|
||||
{
|
||||
animator = GetComponent<Animator>();
|
||||
animator.Play(clip.name);
|
||||
}
|
||||
|
||||
private void LateUpdate()
|
||||
private void LateUpdate() // Updates the animation 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);
|
||||
animator.SetBool("block", block);
|
||||
}
|
||||
|
||||
public void SetState(AnimationState state)
|
||||
public void SetState(AnimationState state) // Sets the animation state
|
||||
{
|
||||
this.state = state;
|
||||
}
|
||||
|
||||
public void Punch()
|
||||
public void Punch() // Triggers punch animation
|
||||
{
|
||||
animator.SetTrigger("punch");
|
||||
}
|
||||
@@ -7,7 +7,7 @@ public class Block : MonoBehaviour
|
||||
public bool blocking = false;
|
||||
private InputActionAsset actions;
|
||||
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 void Start()
|
||||
@@ -15,25 +15,25 @@ public class Block : MonoBehaviour
|
||||
actions = GetComponent<PlayerInput>().actions;
|
||||
}
|
||||
|
||||
private void Update()
|
||||
private void Update() // Player blocks when "block" is pressed
|
||||
{
|
||||
InputAction blockAction = actions.FindAction("Block");
|
||||
if (blockAction.ReadValue<float>() == 1f)
|
||||
{
|
||||
if (!blocking)
|
||||
{
|
||||
blockPressTime = Time.time;
|
||||
blockPressTime = Time.time; // Start parry timer
|
||||
}
|
||||
blocking = true;
|
||||
}
|
||||
else
|
||||
{
|
||||
if (blocking)
|
||||
if (blocking) // Successful parry if blocked in time
|
||||
{
|
||||
float pressDuration = Time.time - blockPressTime;
|
||||
if (pressDuration <= parryThreshold)
|
||||
{
|
||||
Parry();
|
||||
Parry();
|
||||
}
|
||||
else
|
||||
{
|
||||
@@ -7,16 +7,13 @@ using UnityEngine;
|
||||
[RequireComponent(typeof(RespawnOnTriggerEnter))]
|
||||
public class Damageable : MonoBehaviour
|
||||
{
|
||||
public float force = 50f;
|
||||
public float force = 50f; // Force applied when hit
|
||||
public float damage = 0f;
|
||||
public float maxDamage = 1000f;
|
||||
public int lives = 3;
|
||||
public float maxDamage = 1000f; // Set max health
|
||||
public int lives = 0;
|
||||
private Animator animator;
|
||||
|
||||
public bool damageSelfDebug = false;
|
||||
|
||||
public bool dying = false;
|
||||
|
||||
public event System.Action<GameObject> OnPlayerPunched;
|
||||
|
||||
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"))
|
||||
{
|
||||
//print($"{name}: Ouch");
|
||||
Damage(collision.transform.parent.gameObject);
|
||||
}
|
||||
}
|
||||
|
||||
private void Damage(GameObject damageSource)
|
||||
private void Damage(GameObject damageSource) // Damages player
|
||||
{
|
||||
if (dying) return;
|
||||
|
||||
float actualForce = damageSource.GetComponent<Damageable>().force;
|
||||
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);
|
||||
return;
|
||||
}
|
||||
else
|
||||
else // Player does less damage if punching a blocking player
|
||||
{
|
||||
actualForce /= 4;
|
||||
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);
|
||||
}
|
||||
@@ -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;
|
||||
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)
|
||||
{
|
||||
@@ -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);
|
||||
animator.SetBool("die", false);
|
||||
dying = false;
|
||||
}
|
||||
|
||||
public void Respawn()
|
||||
public void Respawn() // Respawns player to the spawnPosition and resets damage/health bar
|
||||
{
|
||||
transform.position = GameManager.Instance.spawnPosition;
|
||||
if (TryGetComponent<Rigidbody2D>(out var rb))
|
||||
@@ -1,7 +1,6 @@
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
|
||||
// This won scene thing is just duct taped on for the presentation.
|
||||
public class PlayerCameraMovement : MonoBehaviour
|
||||
{
|
||||
private Vector3 start;
|
||||
@@ -10,7 +9,6 @@ public class PlayerCameraMovement : MonoBehaviour
|
||||
public float speed;
|
||||
private GameObject playerThatWon;
|
||||
public float lowerBound;
|
||||
|
||||
public bool winScene = false;
|
||||
|
||||
private void Start()
|
||||
@@ -20,7 +18,7 @@ public class PlayerCameraMovement : MonoBehaviour
|
||||
|
||||
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)
|
||||
{
|
||||
@@ -39,6 +37,7 @@ public class PlayerCameraMovement : MonoBehaviour
|
||||
|
||||
return;
|
||||
}
|
||||
// Moves the camera to follow the players
|
||||
List<GameObject> players = GameManager.players;
|
||||
if (players.Count == 0) return;
|
||||
Vector3 playerAverage = Vector3.zero;
|
||||
@@ -70,7 +69,7 @@ public class PlayerCameraMovement : MonoBehaviour
|
||||
playerThatWon = player;
|
||||
}
|
||||
|
||||
private GameObject FindWinner()
|
||||
private GameObject FindWinner() // Finds the player that won
|
||||
{
|
||||
foreach (GameObject player in GameManager.players)
|
||||
{
|
||||
@@ -23,9 +23,8 @@ public class PlayerManager : MonoBehaviour
|
||||
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)
|
||||
{
|
||||
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);
|
||||
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)
|
||||
{
|
||||
@@ -70,7 +69,7 @@ public class PlayerManager : MonoBehaviour
|
||||
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];
|
||||
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);
|
||||
}
|
||||
|
||||
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 _))
|
||||
{
|
||||
@@ -18,20 +18,20 @@ public class PlayerMovement : MonoBehaviour
|
||||
|
||||
[Header("Movement")]
|
||||
public float walkSpeed;
|
||||
public float walkSpeedFactor = 1f;
|
||||
public float maxSpeed = 5f;
|
||||
public float walkSpeedFactor = 1f; // Sets walk speed
|
||||
public float maxSpeed = 5f; // Sets max speed
|
||||
public float maxSpeedOverride;
|
||||
public float slowdownMultiplier = 10f;
|
||||
public float slowdownMultiplier = 10f; // Sets slow walk speed
|
||||
public float virtualAxisX;
|
||||
public float virtualButtonJump;
|
||||
public float virtualButtonJumpLastFrame;
|
||||
public float turnaroundMultiplier = 2;
|
||||
public float turnaroundMultiplier = 2; // Sets speed when turning around
|
||||
public float walkSmooth;
|
||||
public float secondsToFullSpeed;
|
||||
public float jumpSpeed;
|
||||
public float coyoteTime;
|
||||
public float jumpLenience;
|
||||
public float timeUnableToBeDeclaredNotJumping = 0.1f;
|
||||
public float timeUnableToBeDeclaredNotJumping = 0.1f; // Jump threshold
|
||||
public float groundCheckDistance;
|
||||
|
||||
private Rigidbody2D body;
|
||||
@@ -42,19 +42,15 @@ public class PlayerMovement : MonoBehaviour
|
||||
private Damageable damageable;
|
||||
|
||||
private bool jumpInputStillValid = false;
|
||||
private float lastTimeJumpPressed;
|
||||
|
||||
private bool canBeDeclaredNotJumping = true;
|
||||
|
||||
private bool jumpPhysics;
|
||||
|
||||
private bool jumping;
|
||||
|
||||
private float lastTimeJumpPressed;
|
||||
private float lastTimeOnGround;
|
||||
|
||||
private Vector3 positionLastFrame;
|
||||
|
||||
void Start()
|
||||
void Start() // Sets up player components
|
||||
{
|
||||
maxSpeedOverride = maxSpeed;
|
||||
GetComponent<RespawnOnTriggerEnter>().spawnPoint = transform.position;
|
||||
@@ -69,10 +65,10 @@ public class PlayerMovement : MonoBehaviour
|
||||
playerText.text = input.playerIndex.ToString();
|
||||
}
|
||||
|
||||
private void Update()
|
||||
private void Update() // Updates player movement
|
||||
{
|
||||
if (GameManager.Instance != null && GameManager.Instance.gameOver) maxSpeed = 1f;
|
||||
if (damageable.dying/* || (GameManager.Instance != null && GameManager.Instance.gameOver)*/) return;
|
||||
if (damageable.dying) return;
|
||||
|
||||
Jump();
|
||||
|
||||
@@ -88,12 +84,12 @@ public class PlayerMovement : MonoBehaviour
|
||||
Land();
|
||||
}
|
||||
|
||||
private void LateUpdate()
|
||||
private void LateUpdate()
|
||||
{
|
||||
Animate();
|
||||
}
|
||||
|
||||
private void Animate()
|
||||
private void Animate() // Sets player animation
|
||||
{
|
||||
if (!IsPhysicallyGrounded())
|
||||
animationPlayer.SetState(AnimationPlayer.AnimationState.Jump);
|
||||
@@ -111,7 +107,7 @@ public class PlayerMovement : MonoBehaviour
|
||||
animationPlayer.backwards = false;
|
||||
}
|
||||
|
||||
private void Land()
|
||||
private void Land() // Stops jumping when player lands
|
||||
{
|
||||
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)
|
||||
{
|
||||
jumpInputStillValid = true;
|
||||
@@ -145,7 +139,7 @@ public class PlayerMovement : MonoBehaviour
|
||||
}
|
||||
}
|
||||
|
||||
private void JumpPhysics()
|
||||
private void JumpPhysics() // Applies jump physics
|
||||
{
|
||||
if (jumpPhysics)
|
||||
{
|
||||
@@ -165,14 +159,14 @@ public class PlayerMovement : MonoBehaviour
|
||||
body.AddForce(Vector2.down * jumpSpeed);
|
||||
}
|
||||
|
||||
private IEnumerator NotJumpingDelay()
|
||||
private IEnumerator NotJumpingDelay() // Sets jump threshold
|
||||
{
|
||||
canBeDeclaredNotJumping = false;
|
||||
yield return new WaitUntil(() => !IsBasicallyGrounded());
|
||||
canBeDeclaredNotJumping = true;
|
||||
}
|
||||
|
||||
private void HorizontalMovement()
|
||||
private void HorizontalMovement() // Sets player horizontal movement
|
||||
{
|
||||
float temporaryMax = IsPhysicallyGrounded() ? maxSpeedOverride : Mathf.Infinity;
|
||||
float temporarySlowdown = IsPhysicallyGrounded() ? slowdownMultiplier : 1;
|
||||
@@ -184,7 +178,6 @@ public class PlayerMovement : MonoBehaviour
|
||||
|
||||
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));
|
||||
}
|
||||
|
||||
@@ -201,7 +194,7 @@ public class PlayerMovement : MonoBehaviour
|
||||
positionLastFrame = transform.position;
|
||||
}
|
||||
|
||||
private void UpdateVirtualAxis()
|
||||
private void UpdateVirtualAxis() // Updates virtual axis
|
||||
{
|
||||
virtualButtonJump = input.actions.FindAction("Action").ReadValue<float>();
|
||||
virtualButtonJumpLastFrame = input.actions.FindAction("Action").WasPressedThisFrame() ? 1 : 0;
|
||||
@@ -210,7 +203,7 @@ public class PlayerMovement : MonoBehaviour
|
||||
return;
|
||||
}
|
||||
|
||||
public bool IsBasicallyGrounded()
|
||||
public bool IsBasicallyGrounded() // Checks if player is on land within a threshold
|
||||
{
|
||||
if (IsPhysicallyGrounded())
|
||||
{
|
||||
@@ -225,7 +218,7 @@ public class PlayerMovement : MonoBehaviour
|
||||
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 rightCheck = Physics2D.Raycast(GetPointInBoxCollider(collide, 1, -1), Vector2.down, groundCheckDistance, ground);
|
||||
@@ -239,7 +232,7 @@ public class PlayerMovement : MonoBehaviour
|
||||
return false;
|
||||
}
|
||||
|
||||
public Vector2 GetPointInBoxCollider(BoxCollider2D boxCollider2D, float horizontal, float vertical)
|
||||
public Vector2 GetPointInBoxCollider(BoxCollider2D boxCollider2D, float horizontal, float vertical)
|
||||
{
|
||||
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;
|
||||
}
|
||||
@@ -16,7 +16,7 @@ public class Punch : MonoBehaviour
|
||||
actions = GetComponent<PlayerInput>().actions;
|
||||
}
|
||||
|
||||
private void Update()
|
||||
private void Update() // Executes punch when 'punch' is pressed
|
||||
{
|
||||
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();
|
||||
DisableCancellation();
|
||||
GetComponent<PlayerMovement>().maxSpeedOverride = 1f;
|
||||
//OnPlayerPunched?.Invoke(gameObject);
|
||||
GetComponent<PlayerMovement>().maxSpeedOverride = 1f; // Slows player down when punching
|
||||
}
|
||||
|
||||
public void EnableHurtbox()
|
||||
@@ -53,7 +52,7 @@ public class Punch : MonoBehaviour
|
||||
cancelable = true;
|
||||
}
|
||||
|
||||
public void ReturnToMaxSpeed()
|
||||
public void ReturnToMaxSpeed() // Resets player speed after punch
|
||||
{
|
||||
GetComponent<PlayerMovement>().maxSpeedOverride = GetComponent<PlayerMovement>().maxSpeed;
|
||||
}
|
||||
@@ -3,25 +3,15 @@ using UnityEngine;
|
||||
public class TeleportPlatform : MonoBehaviour
|
||||
{
|
||||
public Vector2 teleportPoint;
|
||||
//public bool teleportPosition = false;
|
||||
public string teleportTag;
|
||||
public string playerTag = "Player";
|
||||
|
||||
|
||||
public bool isPlatform = true;
|
||||
|
||||
//private void Start()
|
||||
//{
|
||||
//if (teleportPosition)
|
||||
//{
|
||||
//teleportPoint = transform.position;
|
||||
//}
|
||||
//}
|
||||
|
||||
private void OnTriggerEnter2D(Collider2D collision)
|
||||
{
|
||||
if (!isPlatform)
|
||||
{
|
||||
// Teleports the platform
|
||||
if (collision.CompareTag(teleportTag))
|
||||
{
|
||||
transform.position = teleportPoint;
|
||||
@@ -33,6 +23,7 @@ public class TeleportPlatform : MonoBehaviour
|
||||
}
|
||||
else
|
||||
{
|
||||
// Teleports the player
|
||||
if (collision.CompareTag(playerTag))
|
||||
{
|
||||
collision.transform.position = teleportPoint;
|
||||
@@ -12,16 +12,18 @@ public class UseItem : MonoBehaviour
|
||||
{
|
||||
if (isHoldingItem)
|
||||
{
|
||||
// Keeps hat on the player's head
|
||||
heldItem.transform.position = transform.position + Vector3.up;
|
||||
if (GameManager.gameMode == GameManager.GameMode.keepAway)
|
||||
{
|
||||
// Adds time to the player's leaderboard standing
|
||||
holdTime += Time.deltaTime;
|
||||
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)
|
||||
{
|
||||
@@ -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;
|
||||
isHoldingItem = true;
|
||||
@@ -43,7 +45,7 @@ public class UseItem : MonoBehaviour
|
||||
}
|
||||
}
|
||||
|
||||
public void DropItem()
|
||||
public void DropItem() // Player drops hat when hit
|
||||
{
|
||||
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