示例#1
0
    //接受伤害函数
    protected virtual void ReceiveDamage(Damag dmg)
    {
        //如果不在免疫时间内,则会被造成伤害
        if (Time.time - lastImmune > ImmuneTime)
        {
            //重置免疫时间
            lastImmune = Time.time;

            //造成伤害
            hitPoint -= dmg.damageAmount;

            //被击退
            pushDirection = (transform.position - dmg.origin).normalized * dmg.pushForce;
        }

        //显示造成伤害UI
        //舍弃原因:敌人或者Player受伤都显示同类UI,较为混乱;且因为BoxCollider2D过小,高速碰撞后易出现穿透bug
        //GameManager.instance.ShowText(dmg.damageAmount.ToString(), 25, Color.red, transform.position, Vector3.zero, 0.5f);

        //如果对象血量低于0,则死亡
        if (hitPoint <= 0)
        {
            hitPoint = 0;
            Death();
        }
    }
示例#2
0
    //Player受伤函数: 减血,怒气值增加,刷新生命值UI
    protected override void ReceiveDamage(Damag dmg)
    {
        if (!isAlive)
        {
            return;
        }

        //如果不在免疫时间内,则会被造成伤害
        if (Time.time - lastImmune > ImmuneTime)
        {
            lastImmune    = Time.time;
            hitPoint     -= dmg.damageAmount;
            pushDirection = (transform.position - dmg.origin).normalized * dmg.pushForce;

            //怒气值系统:
            //如果正在释放技能中,则无法积累怒气
            if (!GameManager.instance.weapon.raging)
            {
                OnRageChange(dmg.damageAmount);
            }
        }

        if (hitPoint <= 0)
        {
            hitPoint = 0;
            Death();
        }

        GameManager.instance.OnUIChange();
    }
示例#3
0
    //Player受伤函数:
    protected override void ReceiveDamage(Damag dmg)
    {
        if (!isAlive)
        {
            return;
        }
        //造成伤害
        base.ReceiveDamage(dmg);

        //更新UI
        GameManager.instance.OnHitpointChange();
    }
示例#4
0
    protected override void OnCollide(Collider2D coll)
    {
        if (coll.tag == "Fighter" && coll.name == "Player")
        {
            Damag dmg = new Damag
            {
                damageAmount = damage,
                origin       = transform.position,
                pushForce    = pushForce
            };

            coll.SendMessage("ReceiveDamage", dmg);
        }
    }
示例#5
0
    protected override void ReceiveDamage(Damag dmg)
    {
        if (Time.time - lastImmune > ImmuneTime)
        {
            lastImmune    = Time.time;
            hitPoint     -= dmg.damageAmount;
            pushDirection = (transform.position - dmg.origin).normalized * dmg.pushForce;
        }

        //如果对象血量低于0,则死亡
        if (hitPoint <= 0)
        {
            hitPoint = 0;
            Death();
        }
    }
    private void OnCollide(Collider2D coll)
    {
        if (coll.tag == "Fighter")
        {
            if (coll.name == "Player")
            {
                return;
            }

            Damag dmg = new Damag
            {
                //敌人受到的伤害/击退距离为当前武器的2倍
                damageAmount = GameManager.instance.weapon.damagePoint[GameManager.instance.weapon.weaponLevel] * 2,
                origin       = transform.position,
                pushForce    = GameManager.instance.weapon.pushForce[GameManager.instance.weapon.weaponLevel] * 2
            };

            //发送消息给被碰撞物体,调用其接受伤害函数(Fighter类内)
            coll.SendMessage("ReceiveDamage", dmg);
        }
    }
示例#7
0
    //武器碰撞造成伤害函数:
    //注当为idle状态下BoxCollider被禁用,故只有在Swing状态下才可检测
    protected override void OnCollide(Collider2D coll)
    {
        //必须为可被伤害类物体才可进行伤害检验
        if (coll.tag == "Fighter")
        {
            //武器不可伤害到玩家
            if (coll.name == "Player")
            {
                return;
            }

            //其余即为敌人
            Damag dmg = new Damag
            {
                //敌人受到的伤害/击退距离由各等级的武器决定
                damageAmount = damagePoint[weaponLevel],
                origin       = transform.position,
                pushForce    = pushForce[weaponLevel]
            };

            //发送消息给被碰撞物体,调用其接受伤害函数(Fighter类内)
            coll.SendMessage("ReceiveDamage", dmg);
        }
    }