Beispiel #1
0
    void TakeEffect()
    {
        if (attack == null)
        {
            return;
        }
        var hits = Physics2D.CircleCastAll(target, damageRadui, Vector2.zero);

        if (hits != null && hits.Length > 0)
        {
            for (int i = 0; i < hits.Length; i++)
            {
                GAFEnemy gafEnemy = hits[i].collider.gameObject.GetComponentInParent <GAFEnemy>();
                if (gafEnemy == null)
                {
                    gafEnemy = hits[i].collider.gameObject.GetComponent <GAFEnemy>();
                }

                if (gafEnemy != null)
                {
                    gafEnemy.TakeDamage(attack.GetAttack());
                }
            }
        }
    }
Beispiel #2
0
    public void Shoot(Vector3 postion)
    {
        //Debug.Log (postion);
        deltaTime = 0;
        canShoot  = false;
        anim.SetTrigger("isShooting");
        PlayMuzzleEffect();
        PlaySignEffect();
        PlayShootAudio();
        ShowBullet(postion);
        ShowShell();
        //更新子弹数量显示
        curMagSize -= 1;
        UpdateBulletDisplay();
        if (shakeWhenShoot)
        {
            ShakeBackground();
        }
        RaycastHit2D rayhit     = Physics2D.Raycast(postion, Vector2.zero);
        bool         isHitEnemy = false;

        if (rayhit.collider != null)
        {
            GAFEnemy gafEnemy = rayhit.collider.gameObject.GetComponentInParent <GAFEnemy>();
            if (gafEnemy == null)
            {
                gafEnemy = rayhit.collider.gameObject.GetComponent <GAFEnemy>();
            }
            if (gafEnemy != null)
            {
                // Debug.Log(gafEnemy.name);
                //Debug.Log(rayhit.collider.GetType());
                if (rayhit.collider.GetType() == typeof(CircleCollider2D))
                {
                    gafEnemy.TakeDamage(attack, true);
                }
                else
                {
                    gafEnemy.TakeDamage(attack);
                }
                isHitEnemy = true;
            }

            Shootable shootable = rayhit.collider.GetComponent <Shootable>();
            if (shootable != null)
            {
                shootable.TakeDemage(attack);
                isHitEnemy = true;
            }

            //判断是否击中了箱子
            GameItem item = rayhit.collider.GetComponent <GameItem>();
            if (item)
            {
                item.TakeDamage(attack);
                isHitEnemy = true;
            }
        }
        if (!isHitEnemy)
        {
            PlaySignImpactEffect(postion);
        }
    }