Search Results for

    Show / Hide Table of Contents

    Class GameManager

    This class controls the main game logic, like starting the game, keeping track of players, handling game modes, and deciding when the game ends.

    Inheritance
    object
    GameManager
    Namespace: Game
    Assembly: cs.temp.dll.dll
    Syntax
    public class GameManager : MonoBehaviour

    Fields

    gameMode

    The current game mode (e.g., free-for-all, keep-away, or obstacle course).

    Declaration
    public static GameManager.GameMode gameMode
    Field Value
    Type Description
    GameManager.GameMode

    gameOver

    Whether the game is currently over.

    Declaration
    public bool gameOver
    Field Value
    Type Description
    bool

    gameTimer

    A timer that counts down during the game.

    Declaration
    public GameTimer gameTimer
    Field Value
    Type Description
    GameTimer

    hatObject

    The hat object used in "keep-away" mode.

    Declaration
    public GameObject hatObject
    Field Value
    Type Description
    GameObject

    hatSpawnPositions

    Positions where the hat can spawn in "keep-away" mode.

    Declaration
    public List<Vector2> hatSpawnPositions
    Field Value
    Type Description
    List<><Vector2>

    LeaderboardCanvas

    The canvas that shows the leaderboard during the game.

    Declaration
    public Canvas LeaderboardCanvas
    Field Value
    Type Description
    Canvas

    map

    The name of the map being played.

    Declaration
    public static string map
    Field Value
    Type Description
    string

    music

    Whether the background music is turned on.

    Declaration
    public static bool music
    Field Value
    Type Description
    bool

    obstacleCourseSpawnPosition

    The position where players spawn in obstacle course mode.

    Declaration
    public Vector2 obstacleCourseSpawnPosition
    Field Value
    Type Description
    Vector2

    offset

    The distance between players when they spawn.

    Declaration
    public float offset
    Field Value
    Type Description
    float

    playerColors

    A list of colors assigned to each player.

    Declaration
    public static List<Color> playerColors
    Field Value
    Type Description
    List<><Color>

    playerHoldTimes

    Tracks how long each player has held an item in "keep-away" mode.

    Declaration
    public static Dictionary<GameObject, float> playerHoldTimes
    Field Value
    Type Description
    Dictionary<, ><GameObject, float>

    players

    A list of all the players in the game.

    Declaration
    public static List<GameObject> players
    Field Value
    Type Description
    List<><GameObject>

    spawnPosition

    The position where players spawn at the start of the game.

    Declaration
    public Vector2 spawnPosition
    Field Value
    Type Description
    Vector2

    time

    The total time (in seconds) for the game to run.

    Declaration
    public float time
    Field Value
    Type Description
    float

    TimerCanvas

    The canvas that shows the timer during the game.

    Declaration
    public Canvas TimerCanvas
    Field Value
    Type Description
    Canvas

    Properties

    Instance

    The single instance of this class that can be accessed from anywhere in the game.

    Declaration
    public static GameManager Instance { get; }
    Property Value
    Type Description
    GameManager

    Methods

    AlivePlayers()

    Gets a list of all players who are still alive in the game.

    Declaration
    public List<GameObject> AlivePlayers()
    Returns
    Type Description
    List<><GameObject>

    A list of players who are still active in the game.

    Remarks

    This method checks all players in the game and returns only those who are still active. A player is considered "alive" if their GameObject is active in the scene.

    GameOver()

    Ends the game and determines the winner based on the current game mode.

    Declaration
    public void GameOver()
    Remarks

    This method handles the end-of-game logic, such as stopping the timer, hiding UI elements, and determining the winner based on the GameManager.GameMode. It also triggers the EndGameEvent for any subscribed listeners.

    In "free-for-all" mode, the last alive player is declared the winner. In "keep-away" mode, the player with the longest hold time wins. In "obstacle course" mode, the winner is determined by the ObstacleCourse logic.

    Examples
    GameManager.Instance.GameOver();

    PlayerDied(Damageable)

    Handles what happens when a player dies, like respawning them or ending the game.

    Declaration
    public void PlayerDied(Damageable player)
    Parameters
    Type Name Description
    Damageable player

    The player who died.

    StartGame()

    Sets up the game based on the selected game mode. This includes spawning players and setting their lives.

    Declaration
    public void StartGame()

    UpdatePlayerHoldTime(GameObject, float)

    Updates the hold time for a player and refreshes the leaderboard.

    Declaration
    public void UpdatePlayerHoldTime(GameObject player, float holdTime)
    Parameters
    Type Name Description
    GameObject player

    The player whose hold time is being updated.

    float holdTime

    The new hold time for the player.

    Remarks

    This method updates the player's hold time in the dictionary and refreshes the leaderboard UI. If the player's hold time is higher than before, the leaderboard is re-sorted.

    Events

    EndGameEvent

    Event triggered when the game ends.

    Declaration
    public event GameManager.GameEvent EndGameEvent
    Event Type
    Type Description
    GameManager.GameEvent

    StartGameEvent

    Event triggered when the game starts.

    Declaration
    public event GameManager.GameEvent StartGameEvent
    Event Type
    Type Description
    GameManager.GameEvent
    In This Article
    Back to top Example Unity documentation footer