Exemplo n.º 1
0
    public void GetHurt(AttackData attackData)
    {
        if (enemy_data.isdie)
        {
            return;
        }
        if (!isSuperArmor)
        {
            transform.rotation = attackData.attack_pos.x > transform.position.x ? Quaternion.Euler(0, 180, 0) : Quaternion.identity;
        }
        var hurt = DreamerUtil.GetHurtValue(attackData.hurt_value, model.GetDefend());

        enemy_data.SetHealth(-hurt);

        var pop_text = GameObjectPoolManager.GetPool("pop_text").Get(transform.position + popTextOffset, Quaternion.identity, 0.5f);

        pop_text.GetComponent <PopText>().SetText(Mathf.RoundToInt((float)hurt).ToString(), attackData.isCrit?Color.red:Color.white);

        View.CurrentScene.GetView <GameInfoView>().enemy_health.SetData(enemy_data);

        AudioManager.Instance.PlayOneShot("hit");
        GameObjectPoolManager.GetPool("hit_effect").Get(transform.position + new Vector3(0, 2, 0), Quaternion.identity, 0.5f);


        if (isSuperArmor)
        {
            attackData.attack_type = HitType.普通;
        }


        GameStaticMethod.ChangeChildrenSpriteRendererColor(gameObject, Color.red);

        switch (attackData.attack_type)
        {
        case HitType.普通:
            if (!isGround)
            {
                _rigi.ClearGravity();
            }
            _rigi.ResetVelocity();
            _anim.SetTrigger("hit");
            break;

        case HitType.击退:

            if (!isGround)
            {
                _rigi.ResetVelocity();
                _rigi.ClearGravity();
            }
            else
            {
                _rigi.ResetVelocity();
                _rigi.AddForce(transform.right * hit_back_distance, ForceMode2D.Impulse);
            }
            _anim.SetTrigger("hit");
            break;

        case HitType.击飞:
            _anim.SetTrigger("hitfly");
            _rigi.ResetVelocity();
            if (isGround)
            {
                _rigi.AddForce(new Vector2(transform.right.x * 0.5f, 0.5f).normalized *hit_fly_distance, ForceMode2D.Impulse);
            }
            else
            {
                _rigi.AddForce(new Vector2(transform.right.x * 0.5f, 0).normalized *hit_fly_distance, ForceMode2D.Impulse);
            }
            break;

        case HitType.挑:
            _rigi.ResetVelocity();
            _rigi.AddForce(Vector2.up * 95, ForceMode2D.Impulse);
            break;

        default:
            break;
        }
    }