示例#1
0
    void OnTriggerEnter(Collider other)
    {
        if (ReferenceManager.instance.enemyLayer.ContainsLayer(other.gameObject.layer))
        {
            Vector3     bulletPosition = gameObject.transform.position;
            EnemyHealth enemyHealth    = other.gameObject.GetComponent <EnemyHealth>();

            if (enemyHealth)
            {
                enemyHealth.TakeDamage(Damages, gameObject);
                if (timerContact <= 0.0)
                {
                    timerContact = delay;
                    bouncingNb  -= 1;
                }
                firstEnemy = false;
                enemies.Add(enemyHealth.gameObject);
                newInitialPosition = transform.position;
                if (bouncingNb < 1)
                {
                    Destroy(gameObject);
                }
                else
                {
                    FindNearestEnemy();
                }
            }

            //Impact particules
            ImpactParticlesEmitter emitter = other.gameObject.GetComponent <ImpactParticlesEmitter>();
            if (emitter)
            {
                emitter.InstantiateParticule(bulletPosition, -transform.forward);
            }
            else if (effect != null)
            {
                GameObject particule = Instantiate(effect, transform.position, Quaternion.identity);
                Destroy(particule, 2f);
            }
        }
    }
示例#2
0
    private void OnCollisionEnter(Collision collision)
    {
        if (collisionLayers.ContainsLayer(collision.gameObject.layer))
        {
            Vector3     bulletPosition = gameObject.transform.position;
            EnemyHealth enemyHealth    = collision.gameObject.GetComponent <EnemyHealth>();
            if (enemyHealth)
            {
                enemyHealth.TakeDamage(Damages, gameObject);
            }

            //Impact particules
            ImpactParticlesEmitter emitter = collision.gameObject.GetComponent <ImpactParticlesEmitter>();
            if (emitter)
            {
                emitter.InstantiateParticule(bulletPosition, -transform.forward);
            }
            Destroy(gameObject);

            //Instantiate(bulletHoleGraphic, rayHit.point, Quaternion.Euler(0, 180, 0));
        }
    }