Esempio n. 1
0
    public void OnCollisionEnter2D(Collision2D collision)
    {
        GameObject other  = collision.gameObject;
        Player     player = other.GetComponent <Player>();

        // If the wall is still being laid
        if (stretchWallCoroutine != null)
        {
            // Check if it was your teammate
            Player otherPlayer = other.GetComponent <Player>();
            if (otherPlayer != null &&
                otherPlayer.Team.TeamColor == team.TeamColor)
            {
                return;
            }

            creator.HandleWallCollision();
            GameManager.NotificationManager.NotifyMessage(Message.TronWallDestroyedWhileLaying, creator.gameObject);
            PlayDestroyedParticleEffect();
            Destroy(gameObject);
            return;
        }

        Ball ball = other.GetComponent <Ball>();

        if (ball != null)
        {
            KillSelf();
        }
        else if ((player != null) &&
                 (player.StateManager != null) &&
                 (player.StateManager.CurrentState == State.Dash))
        {
            KillSelf();

            Vector2 knockBackdirection = -player.PlayerMovement.Forward;

            // Duplicate of comment in TronWall:
            // I think it is fine that we don't check for who the owner is here. This may result in
            // multiple people sending out the stun rpc, however, this is
            // the best way to guarantee that a player gets stunned whenever they *should*
            // get stunned. For example, if player 2 just started laying a tron wall and
            // player 1 dashes into it, none of the other players may have the information
            // the player 2 laid a tron wall yet. So it is up to player 2 to send that rpc.
            //
            // I suppose what we could do is check to see if the tron wall is ours of if the player
            // is ours, and then send the rpc.
            player.StateManager.StunNetworked(player.PlayerMovement.CurrentPosition,
                                              knockBackdirection * knockbackOnBreak, wallBreakerStunTime, false);
            GameManager.NotificationManager.NotifyMessage(Message.TronWallDestroyed, other);
        }
    }
Esempio n. 2
0
    public void OnCollisionEnter2D(Collision2D collision)
    {
        GameObject         other        = collision.gameObject;
        Player             player       = other.GetComponent <Player>();
        PlayerStateManager stateManager = other.GetComponent <PlayerStateManager>();

        if (stretchWallCoroutine != null)
        {
            // Check if it was your teammate
            Player otherPlayer = other.GetComponent <Player>();
            if (otherPlayer != null &&
                otherPlayer.team.teamColor == team.teamColor)
            {
                return;
            }

            creator.HandleWallCollision();
            GameManager.instance.notificationManager.NotifyMessage(Message.TronWallDestroyedWhileLaying, creator.gameObject);
            PlayDestroyedParticleEffect();
            Destroy(gameObject);
            return;
        }

        Ball ball = other.GetComponent <Ball>();

        if (ball != null)
        {
            KillSelf();
        }
        else if ((player != null) && (stateManager != null) &&
                 (stateManager.currentState == State.Dash))
        {
            KillSelf();
            PlayerStun playerStun = other.EnsureComponent <PlayerStun>();
            stateManager.AttemptStun(() =>
            {
                Vector3 otherDirection = player.transform.right;
                other.EnsureComponent <Rigidbody2D>().velocity = Vector2.zero;
                playerStun.StartStun(-otherDirection * knockbackOnBreak, creator.wallBreakerStunTime);
                GameManager.instance.notificationManager.NotifyMessage(Message.TronWallDestroyed, other);
            },
                                     playerStun.StopStunned);
        }
    }