Exemplo n.º 1
0
 void OnTriggerStay2D(Collider2D other)
 {
     if (other.gameObject.layer == LayerMask.NameToLayer("Shootable"))
     {
         PC.removeForce();
         Instantiate(explosionEffect, transform.position, transform.rotation);
         Destroy(gameObject);
         if (other.tag == "Enemy")
         {
             hurtEnemy = other.gameObject.GetComponent <enemyHealth>();
             hurtEnemy.takeDamage(damage, 0);
             hurtEnemy.takeDamage(dot, time);
         }
     }
 }
Exemplo n.º 2
0
    //detects the are in front of player for enemies and other objects
    public void HitDetection()
    {
        player.CanControl = true;
        Collider[] cols = new Collider[1];

        Physics.OverlapBoxNonAlloc(transform.TransformPoint(hitBoxLocation), hitboxSize / 2, cols, transform.rotation, hitDetectionLayers);

        if (cols[0] != null)
        {
            enemyHealth e = cols[0].GetComponent <enemyHealth>();
            //if we find an enemy collider, do damage and STUN
            if (e != null)
            {
                //if there's obstacle between enemy and player, continue to next iteration
                if (Physics.Linecast(health.centerPoint, e.centerPoint, blockingLayers))
                {
                    return;
                }

                //stun in enemy script
                e.takeDamage(damage, gameObject);
                SoundEngine.instance.PlaySound("swordImpact", e.transform.position, null);
            }
        }
    }
    private void OnTriggerEnter2D(Collider2D collision)
    {
        enemyHealth enemy = collision.GetComponent <enemyHealth>();

        if (enemy != null)
        {
            enemy.takeDamage(damage);
        }
        Destroy(gameObject);
    }
Exemplo n.º 4
0
    private void OnTriggerEnter2D(Collider2D hitInfo)
    {
        enemyHealth enemy = hitInfo.GetComponent <enemyHealth>();

        if (enemy != null)
        {
            enemy.takeDamage(damage);
        }
        // Instantiate(impactEffect, transform.position, transform.rotation);
        Destroy(gameObject);
    }
Exemplo n.º 5
0
    void Shoot()
    {
        timer = 0.0f;
        if (chamber)
        {
            if (mag != 0)
            {
                mag--;
            }
            else
            {
                chamber = false;
            }
        }
        gunLine.enabled = true;
        gunLine.SetPosition(0, aim.position);

        inventory.equipment [inventory.g].gun.gunAudio.Play();

        spread  = (Random.Range(currAccuracy - 0.1f, 100.0f) - 100.0f);
        spread *= ((Random.Range(0, 10) < 5) ? -0.5f : 0.5f);
        aim.Rotate(new Vector3(0, 0, spread));

        shootRay.origin    = aim.transform.position;
        shootRay.direction = aim.transform.right;

        if (Physics.Raycast(shootRay, out shootHit, range, shootableMask))
        {
            enemyHealth enemyHealth = shootHit.collider.GetComponent <enemyHealth> ();
            if (enemyHealth != null)
            {
                enemyHealth.takeDamage(inventory.equipment [inventory.g].gun.damage);
            }
            Vector3 shotPoint;
            shotPoint.x = shootHit.point.x;
            shotPoint.y = shootHit.point.y;
            shotPoint.z = shootHit.point.z;
            gunLine.SetPosition(1, shotPoint);
        }
        else
        {
            gunLine.SetPosition(1, shootRay.origin + shootRay.direction * range);
        }

        if (currAccuracy > inventory.equipment [inventory.g].gun.accuracy)
        {
            currAccuracy -= 1.0f;
        }

        aim.Rotate(new Vector3(0, 0, -spread));
    }