コード例 #1
0
    public void Damage(CharacterBattle attacker, int damageAmount)
    {
        //damageAmount = 1; Debug.Log("##### No Damage");
        Vector3 bloodDir = (GetPosition() - attacker.GetPosition()).normalized;

        Blood_Handler.SpawnBlood(GetPosition(), bloodDir);

        SoundManager.PlaySound(SoundManager.Sound.CharacterDamaged);
        DamagePopup.Create(GetPosition(), damageAmount, false);
        healthSystem.Damage(damageAmount);
        DamageFlash();
        playerBase.GetUnitAnimation().PlayAnimForced(hitUnitAnimType, GetTargetDir(), 1f, (UnitAnim unitAnim) => {
            PlayIdleAnim();
        }, null, null);

        if (IsDead())
        {
            if (!IsPlayerTeam())
            {
                // Enemy
                if (characterType != Character.Type.EvilMonster && characterType != Character.Type.EvilMonster_2 && characterType != Character.Type.EvilMonster_3)
                {
                    // Don't spawn Flying Body for Evil Monster
                    FlyingBody.Create(GameAssets.i.pfEnemyFlyingBody, GetPosition(), bloodDir);
                    SoundManager.PlaySound(SoundManager.Sound.CharacterDead);
                }
                gameObject.SetActive(false);
            }
            else
            {
                // Player Team
                stats.special = 0;
                SoundManager.PlaySound(SoundManager.Sound.OooohNooo);
            }
            playerBase.GetUnitAnimation().PlayAnimForced(UnitAnim.GetUnitAnim("LyingUp"), 1f, null);
            healthWorldBar.Hide();
            transform.localScale = new Vector3(-1, 1, 1);
            //gameObject.SetActive(false);
            //Destroy(gameObject);
        }
        else
        {
            // Knockback

            /*
             * transform.position += bloodDir * 5f;
             * if (hitUnitAnim != null) {
             *  state = State.Busy;
             *  enemyBase.PlayHitAnimation(bloodDir * (Vector2.one * -1f), SetStateNormal);
             * }
             */
        }
    }
コード例 #2
0
ファイル: PlayerSword.cs プロジェクト: JuliadeBerga/Douglas
    private void HandleAttack()
    {
        if (Input.GetMouseButtonDown(0))
        {
            // Attack
            SetStateAttacking();

            Vector3 attackDir = (UtilsClass.GetMouseWorldPosition() - GetPosition()).normalized;

            EnemyHandler enemyHandler = EnemyHandler.GetClosestEnemy(GetPosition() + attackDir * 4f, 20f);
            if (enemyHandler != null)
            {
                //enemyHandler.Damage(this);
                attackDir          = (enemyHandler.GetPosition() - GetPosition()).normalized;
                transform.position = enemyHandler.GetPosition() + attackDir * -12f;
            }
            else
            {
                transform.position = transform.position + attackDir * 4f;
            }

            Transform swordSlashTransform = Instantiate(GameAssets.i.pfSwordSlash, GetPosition() + attackDir * 13f, Quaternion.Euler(0, 0, UtilsClass.GetAngleFromVector(attackDir)));
            swordSlashTransform.GetComponent <SpriteAnimator>().onLoop = () => Destroy(swordSlashTransform.gameObject);

            UnitAnimType activeAnimType = playerBase.GetUnitAnimation().GetActiveAnimType();
            if (activeAnimType == GameAssets.UnitAnimTypeEnum.dSwordTwoHandedBack_Sword)
            {
                swordSlashTransform.localScale = new Vector3(swordSlashTransform.localScale.x, swordSlashTransform.localScale.y * -1, swordSlashTransform.localScale.z);
                playerBase.GetUnitAnimation().PlayAnimForced(GameAssets.UnitAnimTypeEnum.dSwordTwoHandedBack_Sword2, attackDir, 1f, (UnitAnim unitAnim) => SetStateNormal(), null, null);
            }
            else
            {
                playerBase.GetUnitAnimation().PlayAnimForced(GameAssets.UnitAnimTypeEnum.dSwordTwoHandedBack_Sword, attackDir, 1f, (UnitAnim unitAnim) => SetStateNormal(), null, null);
            }
        }
    }
コード例 #3
0
 public V_UnitAnimation GetUnitAnimation()
 {
     return(playerBase.GetUnitAnimation());
 }