Example #1
0
    public void BeAttaked(BattleUnit attacker)
    {
        var          hurt   = attacker.AttackPower - IgnoreAttack - (DefensePower - attacker.IgnoreDefese);
        var          damage = hurt;
        EffectPrefab attackEffect;

        if (CheckTriggerEffect(out attackEffect))
        {
            if (attackEffect != null)
            {
                attackEffect.SkillEffect.Show(transform, transform.position);

                damage += Config.SkillSettings.Get(attackEffect.SkillID).Hurt;
            }
        }
        int damageValue = damage > 0 ? damage : 0;

        UnitInfo.Hp -= damageValue;
        if (damageValue > 0)
        {
            _bloodEffect.GetComponent <BloodEffect>().SetText(string.Format("<color=#FF0000>-{0}</color>", damageValue));
            _bloodEffect.Show(MainUI.Instance.canvasGroup.transform, transform.position);
        }
        else
        {
            _bloodEffect.GetComponent <BloodEffect>().SetText("<color=#FF00FF>Miss</color>");
            _bloodEffect.Show(MainUI.Instance.canvasGroup.transform, transform.position);
        }
        if (UnitInfo.Hp <= 0)
        {
            if (UnitInfo.Uid == Save.Player.UID)
            {
                MainUI.Instance.ShowPanel <RevivePanel>();

                EffectSoundMgr.Instance.PlayDeadSound();
            }
            else if (attacker.UnitInfo.Uid == Save.Player.UID)
            {
                EffectSoundMgr.Instance.PlayKillSound();
            }

            DestroyObject(gameObject);

            GlobalEventManager.Instance.TriggerEvent(new DestroyUnitInfo()
            {
                AttackInfo = attacker.UnitInfo, DeadInfo = _info
            });
        }
        else
        {
            _beAttacked.Show(transform, transform.position);
        }
    }
Example #2
0
    public void Attack()
    {
        EffectSoundMgr.Instance.PlayAttackSound();
        var   effect = _attackEffect.Show(transform, transform.position);
        float angle  = Vector3.Angle(Vector3.up, _moveDirection);

        if (_moveDirection.x > 0)
        {
            angle = -angle;
        }
        Vector3 axis = Vector3.zero;

        effect.transform.localRotation = Quaternion.Euler(0, 0, angle);
        var attackFillter = effect.GetComponentInChildren <AttackColliderFillter>();

        if (attackFillter == null)
        {
            throw new Exception("此单位没有攻击物,单位名字是" + transform.name);
        }
        attackFillter.Init(UnitInfo);
    }