示例#1
0
 // Räjähdyksessä syntyy räjähdysefekti ja viholliset ottavat damagea riippuen siitä, kuinka kaukana ne ovat räjähdystä
 void Explode()
 {
     Instantiate(explosionEffect, transform.position, Quaternion.LookRotation(Vector3.up));
     Collider[] colliders = Physics.OverlapSphere(transform.position, radius);
     foreach (Collider collider in colliders)
     {
         if (collider && collider.tag == "Enemy")
         {
             float distance = Vector3.Distance(collider.transform.position, transform.position);
             enemyHealth = collider.GetComponent <EnemyHealth> ();
             rigidBody   = collider.GetComponent <Rigidbody> ();
             if (enemyHealth != null && rigidBody != null)
             {
                 rigidBody.AddExplosionForce(power, transform.position, forceRadius);
                 if (distance <= maxDamageRadius)
                 {
                     enemyHealth.EnemyTakeDamage(maxExplosionDamage);
                 }
                 else
                 {
                     enemyHealth.EnemyTakeDamage(minExplosionDamage);
                 }
             }
         }
     }
 }
示例#2
0
    void OnTriggerEnter2D(Collider2D other)
    {
        EnemyHealth hp = other.GetComponent <EnemyHealth>();

        if (hp)
        {
            hp.EnemyTakeDamage();
        }

        Destroy(this.gameObject);
    }
	void Update () {
		Collider[] hits = Physics.OverlapSphere (transform.position, radius, zombieLayer);

		foreach (Collider c in hits) {
			if (c.isTrigger) {
				continue;
			}
			attackTarget = c.gameObject.GetComponent<EnemyHealth> ();
			collided = true;

			if (collided) {
				Instantiate (damageEffect, transform.position, transform.rotation);
				attackTarget.EnemyTakeDamage (damageCount);
			}
		}
	}
示例#4
0
    void OnTriggerEnter(Collider other)
    {
        // Jos panos osuu viholliseen, vihollinen ottaa damagea
        EnemyHealth enemyHealth = other.GetComponent <EnemyHealth> ();

        if (enemyHealth != null)
        {
            enemyHealth.EnemyTakeDamage(bulletDamage);
        }
        // Ammus tuhoutuu osuessaan viholliseen ellei maxlevufirerate, jolloin panokset läpäisevät viholliset.
        // Huom taas lvl2 testimielessä!
        if (other.gameObject != bullet && experience.fireRateLevel != 4 && other.gameObject.name != ("Shield"))
        {
            Destroy(gameObject);
        }
    }
	void Update () {
		Collider[] hits = Physics.OverlapSphere (hitPoint.position, radius, enemyLayer);

		foreach (Collider c in hits) {
			if (c.isTrigger) {
				// Skip next lines of code if true
				continue;
			}
			enemyHealth = c.gameObject.GetComponent<EnemyHealth> ();
			collided = true;

			if (collided) {
				Instantiate (attackEffect, hitPoint.position, hitPoint.rotation);
				enemyHealth.EnemyTakeDamage (damageCount);
			}
		}
	}
示例#6
0
    private void ProcessRaycast()
    {
        RaycastHit hit;

        if (Physics.Raycast(FPCamera.transform.position, FPCamera.transform.forward, out hit, range))
        {
            CreateHitImpact(hit);
            EnemyHealth target = hit.transform.GetComponent <EnemyHealth>();

            if (target == null)
            {
                return;
            }

            target.EnemyTakeDamage(damage);
        }
        else
        {
            return;
        }
    }
示例#7
0
    private void ProcessRaycast()
    {
        RaycastHit hit;

        // Shoot out a Ray forwards from the Camera's position with a max range and store data of what was hit within the hit variable.
        if (Physics.Raycast(cam.transform.position, cam.transform.forward, out hit, range))
        {
            CreateHitImpact(hit);
            EnemyHealth target = hit.transform.GetComponent <EnemyHealth>();
            if (target == null)
            {
                return;
            }

            target.EnemyTakeDamage(damage);
        }
        else
        {
            return;
        }
    }
示例#8
0
    //This function when called makes the player shoot.
    void PlayerPrimaryFire()
    {
        gunSource.pitch = Random.Range(minPitch, maxPitch); //Randomize the pitch

        if (currentAmno > 0)                                //When there's amno available
        {
            Vector3 rayOrigin     = mainCamera.ViewportToWorldPoint(new Vector3(.5f, .5f, 0));
            Vector3 fireDirection = mainCamera.transform.forward; //Direction of the shot, shoots forward from the camera

            StartCoroutine(PlayerShootEffect());

            laserLine.SetPosition(0, gunEnd.position);

            currentAmno -= 1;
            gunSource.PlayOneShot(gunShot);
            amnoAmountUI.text = currentAmno + "/" + remainingAmno; //Refresh amno display on the UI

            if (Physics.Raycast(rayOrigin, fireDirection, out hitInfo, shootDistance))
            {
                laserLine.SetPosition(1, hitInfo.point);
                Vector3 offsetPos = new Vector3(hitInfo.point.x, hitInfo.point.y, hitInfo.point.z + (hitInfo.normal.z * .1f));
                Instantiate(bulletHole);
                bulletHole.transform.position = offsetPos;

                if (hitInfo.transform.tag == "Enemy")
                {
                    enemyHealth.EnemyTakeDamage(gunDamage);
                }
            }
            else //If the raycast hits nothing
            {
                laserLine.SetPosition(1, rayOrigin + (fireDirection * shootDistance));
            }
        }
        else //When there's no amno available
        {
            gunSource.PlayOneShot(gunEmptyClick);
        }
    }