Esempio n. 1
0
 void OnCollisionEnter(Collision collision)
 {
     if (!collision.transform.CompareTag("Player"))
     {
         ContactPoint contact = collision.contacts[0];
         print(collision.gameObject.name);
         if (collision.transform.CompareTag("Wall") || collision.transform.CompareTag("Ground"))
         {
             Instantiate(BulletHole, contact.point, Quaternion.identity);
         }
         EnemyAi ghost = collision.gameObject.GetComponentInParent <EnemyAi>();
         if (ghost != null)
         {
             if (ghost.CompareTag("Ghost"))
             {
                 print("hit");
                 ghost.TakeDamage();
             }
         }
         k = Instantiate(explosionEffect, transform.position, Quaternion.identity);
         Destroy(gameObject, 0.08f);
         //Destroy(k, 0.19f);
         GetComponent <MeshRenderer>().enabled   = false;
         GetComponent <SphereCollider>().enabled = false;
         GetComponent <Rigidbody>().velocity     = Vector3.zero;
     }
 }
Esempio n. 2
0
    void OnTriggerEnter2D(Collider2D collider)
    {
        //On hitting the enemy
        EnemyAi enemy = collider.GetComponent <EnemyAi> ();

        if (enemy != null)
        {
            enemy.TakeDamage(damage);
            CameraShake.Instance.Shake();
            Instantiate(dieEffect, transform.position, transform.rotation);
        }
        Destroy(gameObject);
    }
Esempio n. 3
0
    // Attacks all enemies in range
    private void attack()
    {
        animator.SetTrigger("Attack");

        Collider2D[] hitEnemies = Physics2D.OverlapCircleAll(attackPoint.position, attackRange, enemyLayers);
        foreach (Collider2D enemy in hitEnemies)
        {
            EnemyAi target     = enemy.GetComponent <EnemyAi>();
            Boss    bossTarget = enemy.GetComponent <Boss>();
            if (target)
            {
                target.TakeDamage(attackDamage);
            }
            else if (bossTarget)
            {
                bossTarget.TakeDamage(attackDamage);
            }
        }
    }