private void OnTriggerEnter(Collider other)
    {
        if (GameManager.GameState == GameState.Running)
        {
            MatchBurnComponent otherBurnComp =
                other.GetComponent <MatchBurnComponent>();
            if (isCurrentMatch)
            {
                if (otherBurnComp != null)
                {
                    if (otherBurnComp.CompareTag("MatchP1") ||
                        otherBurnComp.CompareTag("MatchP2"))
                    {
                        PassFlame(otherBurnComp);
                    }
                }

                if (other.CompareTag("Bonfire"))
                {
                    reachedBonfire?.Invoke(PlayerIndex);
                }

                if (other.CompareTag("Water"))
                {
                    vfxComponent.Extinguish(true);
                    SignalLossByWater();
                }
            }
        }
    }
    /// <summary>
    /// Transfers player control, burn behaviour and the camera (if in
    /// Coop Mode) to the next match.
    /// </summary>
    /// <param name="other">The collider of the next match to be lit.</param>
    private void PassFlame(MatchBurnComponent otherBurnComp)
    {
        if (!otherBurnComp.isPreviousMatch)
        {
            MatchAudioComponent.StopMatchLoopAudio();

            // Update next match's state
            otherBurnComp.isCurrentMatch = true;
            otherBurnComp.HeadBurnRate   = HeadBurnRate;
            otherBurnComp.StickBurnRate  = StickBurnRate;

            // Update this match's state
            isPreviousMatch  = true;
            gameObject.layer = 11;
            isCurrentMatch   = false;

            int nextPlayerIndex;
            if (GameManager.GameMode == GameMode.Coop)
            {
                nextPlayerIndex = PlayerIndex == 1 ? 0 : 1;
                Vector3 camLocalPos = CamTransform.localPosition;
                CamTransform.SetParent(otherBurnComp.transform);
                otherBurnComp.CamTransform = CamTransform;
                CamTransform.localPosition = camLocalPos;
            }
            else
            {
                nextPlayerIndex = PlayerIndex;
            }
            otherBurnComp.vfxComponent.Ignite();
            flamePassed?.Invoke(nextPlayerIndex);
        }
    }
Beispiel #3
0
    /// <summary>
    /// Finds the move and burn components of the appropriate match when the
    /// game starts and when matches switch.
    /// </summary>
    private void AssignMatchComponents()
    {
        MatchMoveComponent[] moveComponents
            = FindObjectsOfType <MatchMoveComponent>();

        moveComponent =
            moveComponents.FirstOrDefault(m => m.playerIndex == playerIndex &&
                                          m.gameObject.GetComponent <MatchBurnComponent>().isCurrentMatch);

        burnComponent =
            moveComponent.gameObject.GetComponent <MatchBurnComponent>();
    }