Example #1
0
    public bool Damage(int damage, float impact, Transform attackTran, Transform hitTran, Transform ownerTran)
    {
        if (hitTran == null || attackTran == null)
        {
            return(false);
        }

        bool isHit     = false;
        int  hitDamage = 0;

        switch (hitTran.tag)
        {
        case Common.CO.TAG_UNIT:
        case Common.CO.TAG_ENEMY:
            //ユニット
            //被弾方向補正
            Vector3 hitVector  = attackTran.position - hitTran.position;
            float   damageRate = GetHitAngleRate(hitTran, hitVector);
            damage    = (int)(damage * damageRate);
            hitDamage = hitTran.GetComponent <UnitController>().Hit(damage, impact * -hitVector.normalized, ownerTran);
            if (hitDamage > 0)
            {
                SpawnDamageEffect(attackTran, hitTran);
            }
            isHit = true;
            break;

        case Common.CO.TAG_HQ:
        case Common.CO.TAG_ENEMY_HQ:
            //HQ
            hitDamage = hitTran.GetComponent <UnitController>().Hit(damage, ownerTran);
            isHit     = true;
            break;

        case Common.CO.TAG_BREAK_OBSTACLE:
            //破壊可能障害物
            ObstacleController obstacleCtrl = hitTran.GetComponent <ObstacleController>();
            if (ownerTran != null)
            {
                int obstacleSide = obstacleCtrl.GetSide();
                if (obstacleSide != Common.CO.SIDE_UNKNOWN && obstacleSide == Common.Func.GetMySide(ownerTran.tag))
                {
                    damage = 0;
                }
            }
            if (damage > 0)
            {
                hitDamage = obstacleCtrl.Hit(damage, ownerTran);
            }
            if (hitDamage > 0)
            {
                SpawnDamageEffect(attackTran, hitTran);
            }
            isHit = true;
            break;

        case Common.CO.TAG_OBSTACLE:
        case Common.CO.TAG_ARTILLERY_OBSTACLE:
            //障害物
            isHit = true;
            break;
        }

        return(isHit);
    }