示例#1
0
    private void OnCollisionEnter(Collision collision)
    {
        AN_EnemyBaheviour en     = collision.gameObject.GetComponent <AN_EnemyBaheviour>();
        AN_Bullet         bullet = collision.gameObject.GetComponent <AN_Bullet>();

        if (bullet == null) // for shortgun
        {
            if (!EnemyBullet)
            {
                if (en != null)
                {
                    en.CurrentHealth -= Damage;
                    Instantiate(Blood, transform.position, transform.rotation);
                }
                Destroy(gameObject);
            }
            else // enemy bullet
            {
                AN_PlayerParams pr = collision.gameObject.GetComponent <AN_PlayerParams>();
                if (pr != null)
                {
                    pr.CurrentHealth -= Damage;
                    Instantiate(Blood, transform.position, transform.rotation);
                    Destroy(gameObject);
                }
                else if (en == null)
                {
                    Destroy(gameObject);
                }
            }
        }
    }
    private void Start()
    {
        if (ImpulseDamage)
        {
            Collider[] checkObj = Physics.OverlapSphere(transform.position, Radius);
            foreach (var obj in checkObj)
            {
                AN_PlayerParams   pr = obj.GetComponent <AN_PlayerParams>();
                AN_EnemyBaheviour en = obj.GetComponent <AN_EnemyBaheviour>();

                if (pr != null)
                {
                    pr.CurrentHealth -= Damage;
                }
                if (en != null)
                {
                    en.CurrentHealth -= Damage;
                }
            }
        }
    }