Skip to content
Snippets Groups Projects
RoundController.cs 2.07 KiB
Newer Older
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;

public interface IRoundCallback
{
    void OnRoundStart();
    void OnRoundEnd();
}
public class RoundController : MonoBehaviour, IFighterCallback
    public static RoundController instance { get; private set; }
    public List<IRoundCallback> roundCallbacks = new List<IRoundCallback>();
    public bool roundRunning { get; private set; }
    [SerializeField, Tooltip("After the AntiHero died, how many seconds to wait until ending the current round")]
    float delayAfterAntiHeroDeath = 1.75f;

    BaseCameraController cameraController;

    public void StartRound()
        if (roundRunning)
        roundRunning = true;
        roundCallbacks.ForEach(c => c.OnRoundStart());
        // Fighters clear their callbacks every round end
        GameObject.FindGameObjectWithTag("AntiPlayer").GetComponent<Fighter>().callbacks.Add(this);
    }

    public void StopRound()
    {
        if (!roundRunning)
        roundRunning = false;
        roundCallbacks.ForEach(c => c.OnRoundEnd());
    public void ToggleRound()
        if (roundRunning)
        {
            StopRound();
        }
        else
        {
            StartRound();
        }
    public void SetGameSpeed(float multiplier)
Moritz Meyerhof's avatar
Moritz Meyerhof committed
    {
        Time.timeScale = multiplier;
    }

        if (instance == null)
        {
            instance = this;
        }
        else if (instance != this)
        {
            Destroy(gameObject);
        }
        DontDestroyOnLoad(gameObject);

        cameraController = Camera.main.GetComponent<BaseCameraController>();
    public void OnFighterDeath(Fighter fighter)
    {
        // The AntiHero has died
        SetGameSpeed(0.5f);
        cameraController.AnimateToPosition(fighter.transform.position + new Vector3(0f, 0.75f), 1.5f, 0.05f);
        Invoke(nameof(StopRound), delayAfterAntiHeroDeath);