void OnTriggerEnter2D(Collider2D collision)
    {
        if (collision.gameObject.tag == "Wall")
        {
            Destroy(gameObject);
        }

        if (gameObject.CompareTag("Player2Bullet"))
        {
            if (collision.gameObject.tag == "Player1")
            {
                if (PlayerStatusControl_Level2._instance.isPlayer1)
                {
                    if (Player1Status_Level2._instance.damageReflect)
                    {
                        Player2Status_Level2._instance.Damage(Player2Status_Level2._instance.attackAbility);
                        tcpClient.SendHpChange(2, -Mathf.RoundToInt(Player2Status_Level2._instance.attackAbility));
                    }
                    else
                    {
                        if (Player2Status_Level2._instance.playerPower == PlayerPower_Level2.KnightPower && Player1Status_Level2._instance.playerCharacter == PlayerCharacter_Level2.Dragon)
                        {
                            Player1Status_Level2._instance.Damage(Player2Status_Level2._instance.attackAbility + 2);
                            tcpClient.SendHpChange(1, -Mathf.RoundToInt(Player2Status_Level2._instance.attackAbility) - 2);
                        }
                        else
                        {
                            Player1Status_Level2._instance.Damage(Player2Status_Level2._instance.attackAbility);
                            tcpClient.SendHpChange(1, -Mathf.RoundToInt(Player2Status_Level2._instance.attackAbility));
                        }
                    }
                }
                explo = (GameObject)Instantiate(explosion, collision.transform.position, Quaternion.identity);
                Destroy(explo, 1);
                Destroy(gameObject);
            }
        }
        if (gameObject.CompareTag("Player1Bullet"))
        {
            if (collision.gameObject.tag == "Player2")
            {
                if (!PlayerStatusControl_Level2._instance.isPlayer1)
                {
                    if (Player2Status_Level2._instance.damageReflect)
                    {
                        Player1Status_Level2._instance.Damage(Player1Status_Level2._instance.attackAbility);
                        tcpClient.SendHpChange(1, -Mathf.RoundToInt(Player1Status_Level2._instance.attackAbility));
                    }
                    else
                    {
                        if (Player1Status_Level2._instance.playerPower == PlayerPower_Level2.KnightPower && Player2Status_Level2._instance.playerCharacter == PlayerCharacter_Level2.Dragon)
                        {
                            Player2Status_Level2._instance.Damage(Player1Status_Level2._instance.attackAbility + 2);
                            tcpClient.SendHpChange(2, -Mathf.RoundToInt(Player1Status_Level2._instance.attackAbility) - 2);
                        }
                        else
                        {
                            Player2Status_Level2._instance.Damage(Player1Status_Level2._instance.attackAbility);
                            tcpClient.SendHpChange(2, -Mathf.RoundToInt(Player1Status_Level2._instance.attackAbility));
                        }
                    }
                }

                explo = (GameObject)Instantiate(explosion, collision.transform.position, Quaternion.identity);
                Destroy(explo, 1);
                Destroy(gameObject);
            }
        }
    }
Beispiel #2
0
    void CheckPlayer1Trigger(Collider2D collision)
    {
        bool visible          = true;
        bool attackBuffOnArea = false;
        bool speedUpOnRain    = false;

        if (collision.gameObject.CompareTag("DragonPic"))
        {
            if (Player2Status_Level2._instance.playerCharacter != PlayerCharacter_Level2.Dragon &&
                Player1Status_Level2._instance.playerCharacter != PlayerCharacter_Level2.Dragon)
            {
                Player1Status_Level2._instance.playerCharacter = PlayerCharacter_Level2.Dragon;
                Player1Status_Level2._instance.playerPower     = PlayerPower_Level2.Default;
                Player1Status_Level2._instance.originAttack    = 0.0f;
                RemoveCharacterRedCross();
                TurnEffect();
                CharacterRedCrossEffect(collision);
                spriteRender.sprite = sprite[0];
                animator.runtimeAnimatorController = dragonController;
                audioSource.clip = dragonAttack;
                audioSource.Play();
                UpdateFace(playerMove.dir);
                Debug.Log("Player1 turn into Dragon");
            }
            powerIndex = 0;
        }
        else if (collision.gameObject.CompareTag("KnightPic"))
        {
            if (Player2Status_Level2._instance.playerCharacter != PlayerCharacter_Level2.Knight &&
                Player1Status_Level2._instance.playerCharacter != PlayerCharacter_Level2.Knight)
            {
                Player1Status_Level2._instance.playerCharacter = PlayerCharacter_Level2.Knight;
                Player1Status_Level2._instance.playerPower     = PlayerPower_Level2.Default;
                Player1Status_Level2._instance.originAttack    = 0.0f;
                RemoveCharacterRedCross();
                TurnEffect();
                CharacterRedCrossEffect(collision);
                spriteRender.sprite = sprite[1];
                animator.runtimeAnimatorController = knightController;
                audioSource.clip = knightAttack;
                audioSource.Play();
                UpdateFace(playerMove.dir);
                Debug.Log("Player1 turn into Knight");
            }
            powerIndex = 0;
        }
        else if (collision.gameObject.CompareTag("MagicPic"))
        {
            if (Player2Status_Level2._instance.playerCharacter != PlayerCharacter_Level2.Magic &&
                Player1Status_Level2._instance.playerCharacter != PlayerCharacter_Level2.Magic)
            {
                Player1Status_Level2._instance.playerCharacter = PlayerCharacter_Level2.Magic;
                Player1Status_Level2._instance.playerPower     = PlayerPower_Level2.Default;
                Player1Status_Level2._instance.originAttack    = 0.0f;
                RemoveCharacterRedCross();
                TurnEffect();
                CharacterRedCrossEffect(collision);
                spriteRender.sprite = sprite[2];
                animator.runtimeAnimatorController = magicController;
                audioSource.clip = magicAttack;
                audioSource.Play();
                UpdateFace(playerMove.dir);
                Debug.Log("Player1 turn into Magic");
            }
            powerIndex = 0;
        }
        else if (collision.gameObject.CompareTag("AssassinPic"))
        {
            if (Player2Status_Level2._instance.playerCharacter != PlayerCharacter_Level2.Assassin &&
                Player1Status_Level2._instance.playerCharacter != PlayerCharacter_Level2.Assassin)
            {
                Player1Status_Level2._instance.playerCharacter = PlayerCharacter_Level2.Assassin;
                Player1Status_Level2._instance.playerPower     = PlayerPower_Level2.Default;
                Player1Status_Level2._instance.originAttack    = 0.0f;
                RemoveCharacterRedCross();
                TurnEffect();
                CharacterRedCrossEffect(collision);
                spriteRender.sprite = sprite[3];
                animator.runtimeAnimatorController = assassinController;
                audioSource.clip = assassinAttack;
                audioSource.Play();
                UpdateFace(playerMove.dir);
                Debug.Log("Player1 turn into Assassin");
            }
            powerIndex = 0;
        }
        else if (collision.gameObject.CompareTag("BossPic"))
        {
            if (Player2Status_Level2._instance.playerCharacter != PlayerCharacter_Level2.Boss &&
                Player1Status_Level2._instance.playerCharacter != PlayerCharacter_Level2.Boss)
            {
                Player1Status_Level2._instance.playerCharacter = PlayerCharacter_Level2.Boss;
                Player1Status_Level2._instance.playerPower     = PlayerPower_Level2.Default;
                Player1Status_Level2._instance.originAttack    = 0.0f;
                RemoveCharacterRedCross();
                TurnEffect();
                CharacterRedCrossEffect(collision);
                spriteRender.sprite = sprite[4];
                animator.runtimeAnimatorController = bossController;
                audioSource.clip = bossAttack;
                audioSource.Play();
                UpdateFace(playerMove.dir);
                Debug.Log("Player1 turn into Boss");
            }
            powerIndex = 0;
        }
        else if (collision.gameObject.CompareTag("DragonPowerPic"))
        {
            if (Player1Status_Level2._instance.playerCharacter == PlayerCharacter_Level2.Dragon)
            {
                if (collision.gameObject.name == "DragonPowerPic" + powerIndex.ToString())
                {
                    RedCrossEffect(collision);
                    powerIndex++;
                }
                else
                {
                    RemovePowerRedCrossOnMap();
                    powerIndex = 0;
                }
                if (powerIndex == dragonPowerCount)
                {
                    Player1Status_Level2._instance.playerPower  = PlayerPower_Level2.DragonPower;
                    Player1Status_Level2._instance.originAttack = 2;

                    float percent = Player1Status_Level2._instance.hp / Player1Status_Level2._instance.maxHp;
                    Player1Status_Level2._instance.hp    = Mathf.RoundToInt(percent * dragonHp);
                    Player1Status_Level2._instance.maxHp = dragonHp;

                    audioSource.clip = dragonAttack;
                    audioSource.Play();

                    Debug.Log("Player1 has Dragon Power");
                    TurnEffect();
                }
            }
        }
        else if (collision.gameObject.CompareTag("KnightPowerPic"))
        {
            if (Player1Status_Level2._instance.playerCharacter == PlayerCharacter_Level2.Knight)
            {
                if (collision.gameObject.name == "KnightPowerPic" + powerIndex.ToString())
                {
                    RedCrossEffect(collision);
                    powerIndex++;
                }
                else
                {
                    RemovePowerRedCrossOnMap();
                    powerIndex = 0;
                }
                if (powerIndex == knightPowerCount)
                {
                    Player1Status_Level2._instance.playerPower  = PlayerPower_Level2.KnightPower;
                    Player1Status_Level2._instance.originAttack = 2;

                    float percent = Player1Status_Level2._instance.hp / Player1Status_Level2._instance.maxHp;
                    Player1Status_Level2._instance.hp    = Mathf.RoundToInt(percent * knightHp);
                    Player1Status_Level2._instance.maxHp = knightHp;

                    audioSource.clip = knightAttack;
                    audioSource.Play();

                    Debug.Log("Player1 has Knight Power");
                    TurnEffect();
                }
            }
        }
        else if (collision.gameObject.CompareTag("MagicPowerPic"))
        {
            if (Player1Status_Level2._instance.playerCharacter == PlayerCharacter_Level2.Magic)
            {
                if (collision.gameObject.name == "MagicPowerPic" + powerIndex.ToString())
                {
                    RedCrossEffect(collision);
                    powerIndex++;
                }
                else
                {
                    RemovePowerRedCrossOnMap();
                    powerIndex = 0;
                }
                if (powerIndex == magicPowerCount)
                {
                    Player1Status_Level2._instance.playerPower  = PlayerPower_Level2.MagicPower;
                    Player1Status_Level2._instance.originAttack = 2;

                    float percent = Player1Status_Level2._instance.hp / Player1Status_Level2._instance.maxHp;
                    Player1Status_Level2._instance.hp    = Mathf.RoundToInt(percent * magicHp);
                    Player1Status_Level2._instance.maxHp = magicHp;

                    audioSource.clip = magicAttack;
                    audioSource.Play();

                    Debug.Log("Player1 has Magic Power");
                    TurnEffect();
                }
            }
        }
        else if (collision.gameObject.CompareTag("AssassinPowerPic"))
        {
            if (Player1Status_Level2._instance.playerCharacter == PlayerCharacter_Level2.Assassin)
            {
                if (collision.gameObject.name == "AssassinPowerPic" + powerIndex.ToString())
                {
                    RedCrossEffect(collision);
                    powerIndex++;
                }
                else
                {
                    RemovePowerRedCrossOnMap();
                    powerIndex = 0;
                }
                if (powerIndex == assassinPowerCount)
                {
                    Player1Status_Level2._instance.playerPower  = PlayerPower_Level2.AssassinPower;
                    Player1Status_Level2._instance.originAttack = 4;

                    float percent = Player1Status_Level2._instance.hp / Player1Status_Level2._instance.maxHp;
                    Player1Status_Level2._instance.hp    = Mathf.RoundToInt(percent * assassinHp);
                    Player1Status_Level2._instance.maxHp = assassinHp;

                    audioSource.clip = assassinAttack;
                    audioSource.Play();

                    Debug.Log("Player1 has Assassin Power");
                    TurnEffect();
                }
            }
        }
        else if (collision.gameObject.CompareTag("BossPowerPic"))
        {
            if (Player1Status_Level2._instance.playerCharacter == PlayerCharacter_Level2.Boss)
            {
                if (collision.gameObject.name == "BossPowerPic" + powerIndex.ToString())
                {
                    RedCrossEffect(collision);
                    powerIndex++;
                }
                else
                {
                    RemovePowerRedCrossOnMap();
                    powerIndex = 0;
                }
                if (powerIndex == bossPowerCount)
                {
                    Player1Status_Level2._instance.playerPower  = PlayerPower_Level2.BossPower;
                    Player1Status_Level2._instance.originAttack = 2;

                    float percent = Player1Status_Level2._instance.hp / Player1Status_Level2._instance.maxHp;
                    Player1Status_Level2._instance.hp    = Mathf.RoundToInt(percent * bossHp);
                    Player1Status_Level2._instance.maxHp = bossHp;

                    audioSource.clip = bossAttack;
                    audioSource.Play();

                    Debug.Log("Player1 has Boss Power");
                    TurnEffect();
                }
            }
        }
        else if (collision.gameObject.CompareTag("PoisonPic"))
        {
            switch (Player1Status_Level2._instance.playerPower)
            {
            case PlayerPower_Level2.DragonPower:
                break;

            case PlayerPower_Level2.KnightPower:
                if (!Player1Status_Level2._instance.overPoison)
                {
                    if (PlayerStatusControl_Level2._instance.isPlayer1)
                    {
                        Player1Status_Level2._instance.Damage(1);
                        tcpClient.SendHpChange(1, -1);
                    }
                }
                break;

            case PlayerPower_Level2.MagicPower:
                ChangeToArea(collision);
                break;

            case PlayerPower_Level2.AssassinPower:
                if (!PlayerStatusControl_Level2._instance.isPlayer1)
                {
                    BecomeInvisible();
                    visible = false;
                }
                break;

            case PlayerPower_Level2.BossPower:
                break;

            case PlayerPower_Level2.Default:
                if (!Player1Status_Level2._instance.overPoison)
                {
                    if (PlayerStatusControl_Level2._instance.isPlayer1)
                    {
                        Player1Status_Level2._instance.Damage(1);
                        tcpClient.SendHpChange(1, -1);
                    }
                }
                break;
            }
        }
        else if (collision.gameObject.CompareTag("AreaPic"))
        {
            switch (Player1Status_Level2._instance.playerPower)
            {
            case PlayerPower_Level2.DragonPower:
                ChangeToPoison(collision);
                break;

            case PlayerPower_Level2.KnightPower:
                Player1Status_Level2._instance.attackAbility = Player1Status_Level2._instance.originAttack + 2;
                attackBuffOnArea = true;
                break;

            case PlayerPower_Level2.MagicPower:
                break;

            case PlayerPower_Level2.AssassinPower:
                if (!Player1Status_Level2._instance.overArea)
                {
                    if (PlayerStatusControl_Level2._instance.isPlayer1)
                    {
                        Player1Status_Level2._instance.Damage(1);
                        tcpClient.SendHpChange(1, -1);
                    }
                }
                break;

            case PlayerPower_Level2.BossPower:
                break;

            case PlayerPower_Level2.Default:
                if (!Player1Status_Level2._instance.overArea)
                {
                    if (PlayerStatusControl_Level2._instance.isPlayer1)
                    {
                        Player1Status_Level2._instance.Damage(1);
                        tcpClient.SendHpChange(1, -1);
                    }
                }
                break;
            }
        }
        else if (collision.gameObject.CompareTag("AddOnePic"))
        {
            if (collision.gameObject.name == "AddOnePic" + powerIndex.ToString())
            {
                RedCrossEffect(collision);
                powerIndex++;
            }
            else
            {
                RemovePowerRedCrossOnMap();
                powerIndex = 0;
            }
            if (powerIndex == addOneCount)
            {
                if (PlayerStatusControl_Level2._instance.isPlayer1)
                {
                    Player1Status_Level2._instance.Recover(2);
                    tcpClient.SendHpChange(1, 2);
                }
                audioSource.clip = recoverBuff;
                audioSource.Play();
                RecoverEffect();
                Debug.Log("Player1 recorve 1 hp");
            }
        }
        else if (collision.gameObject.CompareTag("AddTwoPic"))
        {
            if (collision.gameObject.name == "AddTwoPic" + powerIndex.ToString())
            {
                RedCrossEffect(collision);
                powerIndex++;
            }
            else
            {
                RemovePowerRedCrossOnMap();
                powerIndex = 0;
            }
            if (powerIndex == addTwoCount)
            {
                if (PlayerStatusControl_Level2._instance.isPlayer1)
                {
                    Player1Status_Level2._instance.Recover(4);
                    tcpClient.SendHpChange(1, 4);
                }
                audioSource.clip = recoverBuff;
                audioSource.Play();
                RecoverEffect();
                Debug.Log("Player1 recorve 2 hp");
            }
        }
        else if (collision.gameObject.CompareTag("OverPoisonPic"))
        {
            if (collision.gameObject.name == "OverPoisonPic" + powerIndex.ToString())
            {
                RedCrossEffect(collision);
                powerIndex++;
            }
            else
            {
                RemovePowerRedCrossOnMap();
                powerIndex = 0;
            }
            if (powerIndex == overPoisonCount)
            {
                Player1Status_Level2._instance.overPoison = true;
                audioSource.clip = overBuff;
                audioSource.Play();
                Debug.Log("Player1 is poison no effect");
            }
        }
        else if (collision.gameObject.CompareTag("OverAreaPic"))
        {
            if (collision.gameObject.name == "OverAreaPic" + powerIndex.ToString())
            {
                RedCrossEffect(collision);
                powerIndex++;
            }
            else
            {
                RemovePowerRedCrossOnMap();
                powerIndex = 0;
            }
            if (powerIndex == overAreaCount)
            {
                Player1Status_Level2._instance.overArea = true;
                audioSource.clip = overBuff;
                audioSource.Play();
                Debug.Log("Player1 is area no effect");
            }
        }
        else if (collision.gameObject.CompareTag("DamageReflectPic"))
        {
            if (collision.gameObject.name == "DamageReflectPic" + powerIndex.ToString())
            {
                RedCrossEffect(collision);
                powerIndex++;
            }
            else
            {
                RemovePowerRedCrossOnMap();
                powerIndex = 0;
            }
            if (powerIndex == damageReflectCount)
            {
                Player1Status_Level2._instance.damageReflect = true;
                audioSource.clip = enhanceBuff;
                audioSource.Play();
                Debug.Log("Player1 is damage Reflect");
            }
        }
        else if (collision.gameObject.CompareTag("AttackBuffPic"))
        {
            if (collision.gameObject.name == "AttackBuffPic" + powerIndex.ToString())
            {
                RedCrossEffect(collision);
                powerIndex++;
            }
            else
            {
                RemovePowerRedCrossOnMap();
                powerIndex = 0;
            }
            if (powerIndex == attackBuffCount)
            {
                Player1Status_Level2._instance.attackBuff = true;
                audioSource.clip = enhanceBuff;
                audioSource.Play();
                Debug.Log("Player1 is attack buff");
            }
        }
        else if (collision.gameObject.CompareTag("Rain"))
        {
            speedUpOnRain      = true;
            playerMove.speedUp = 2f;
            powerIndex         = 0;
        }
        else if (collision.gameObject.CompareTag("Player1Bullet") || collision.gameObject.CompareTag("Player2Bullet") || collision.gameObject.CompareTag("PlayerCube"))
        {
        }
        else
        {
            RemovePowerRedCrossOnMap();
            powerIndex = 0;
        }
        if (visible || Player2Status_Level2._instance.playerPower == PlayerPower_Level2.MagicPower)
        {
            BecomeVisible();
        }
        if (!attackBuffOnArea)
        {
            Player1Status_Level2._instance.attackAbility = Player1Status_Level2._instance.originAttack;
        }
        if (!speedUpOnRain)
        {
            playerMove.speedUp = 1f;
        }
    }