Ejemplo n.º 1
0
    void OnTriggerEnter2D(Collider2D collision)
    {
        ScoreService scoreService = ScoreService.getInstance();

        Debug.Log(collision.tag);
        if (collision.gameObject.CompareTag("Player1"))
        {
            DifficultyService.difficulty = 2;
            LifeService.player1Life      = 3;
            LifeService.player2Life      = 3;
            SceneManager.LoadScene(isCoop? "Cinematica":"GanarFalsa");
        }
        else if (collision.gameObject.CompareTag("Player2"))
        {
            DifficultyService.difficulty = 2;
            LifeService.player1Life      = 3;
            LifeService.player2Life      = 3;
            SceneManager.LoadScene(isCoop? "Cinematica":"GanarReal");
        }
        else if (collision.gameObject.CompareTag("Target"))
        {
            Debug.Log("Missed");
            PickableObject target = collision.gameObject.GetComponent <PickableObject> ();
            if (target.isCatchable != player.isCatcher)
            {
                if (player.isPlayerOne)
                {
                    scoreService.increasePlayer1Score(target.score);
                }
                else
                {
                    scoreService.increasePlayer2Score(target.score);
                }
            }
            else if (target.canDamage)
            {
                if (player.isPlayerOne)
                {
                    scoreService.decreasePlayer1Score(target.score);
                    lifeService.player1LosesLife();
                }
                else
                {
                    scoreService.decreasePlayer2Score(target.score);
                    lifeService.player2LosesLife();
                }
                target.canDamage = false;

                Swapper.upperScreenCanCatch = !Swapper.upperScreenCanCatch;
                Destroy(collision.gameObject);
            }
        }
    }
    private void OnTriggerEnter2D(Collider2D collision)
    {
        if (collision.gameObject.CompareTag("Target"))
        {
            Debug.Log("Target hitted!");
            PickableObject target             = collision.gameObject.GetComponent <PickableObject> ();
            bool           playerHasZeroLives = false;
            if (target.isCatchable == isCatcher)
            {
                if (isPlayerOne)
                {
                    scoreService.increasePlayer1Score(target.score);
                }
                else
                {
                    scoreService.increasePlayer2Score(target.score);
                }
            }
            else if (target.canDamage)
            {
                if (isPlayerOne)
                {
                    scoreService.decreasePlayer1Score(target.score);
                    playerHasZeroLives = lifeService.player1LosesLife();
                }
                else
                {
                    scoreService.decreasePlayer2Score(target.score);
                    playerHasZeroLives = lifeService.player2LosesLife();
                }

                Debug.Log("Swap");

                Swapper.upperScreenCanCatch = !Swapper.upperScreenCanCatch;
            }
            target.canDamage = false;
            target.PlaySound();
            Destroy(collision.gameObject);
        }
    }