Пример #1
0
    void OnCollisionEnter(Collision col)
    {
        if (col.gameObject.tag.Equals("Player"))
        {
            // Find the ShipHealth script associated with the rigidbody.
            ShipHealth targetHealth = target.GetComponent <ShipHealth> ();

            // Calculate the amount of damage the target should take based on it's distance from the shell.

            // Move the instantiated explosion prefab to the Ship's position and turn it on.
            m_ExplosionParticles.transform.position = transform.position;
            m_ExplosionParticles.gameObject.SetActive(true);

            // Play the particle system of the Ship exploding.
            m_ExplosionParticles.Play();

            // Play the Ship explosion sound effect.
            m_ExplosionAudio.Play();

            // Deal this damage to the Ship.
            targetHealth.TakeDamage(damage);

            // Destroy(gameObject);
            gameObject.SetActive(false);
        }
    }
    private IEnumerator DamageOverTime()
    {
        while (countingDown)
        {
            yield return(new WaitForSeconds(1f));

            h.TakeDamage(damagePerSecond);
        }
    }
Пример #3
0
        public void ShipTakeDamage(int damage, int expected)
        {
            // Use the Assert class to test conditions
            ShipHealth ship = new ShipHealth(10);

            ship.TakeDamage(damage);

            Assert.That(ship.GetHealth(), Is.EqualTo(expected));
        }
Пример #4
0
 private void OnTriggerStay(Collider other)
 {
     if (other.tag == "Player")
     {
         Destroy(this.gameObject);
         Destroy(laserEnd.gameObject);
         shipHealth.TakeDamage(damage);
     }
 }
Пример #5
0
 // SphereCast to checks every Object within it
 void Explode()
 {
     Collider[] colliders = Physics.OverlapSphere(transform.position, m_explosionRadius);
     for (int i = 0; i < colliders.Length; i++)
     {
         ShipHealth targetInRange = colliders[i].GetComponent <ShipHealth>();
         if (targetInRange != null)
         {
             targetInRange.TakeDamage(m_damage);
         }
     }
 }
Пример #6
0
    private void OnTriggerEnter(Collider other)
    {
        // Collect all the colliders in a sphere from the shell's current position to a radius of the explosion radius.
        Collider[] colliders = Physics.OverlapSphere(transform.position, m_ExplosionRadius, m_ShipMask);

        // Go through all the colliders...
        for (int i = 0; i < colliders.Length; i++)
        {
            // ... and find their rigidbody.
            Rigidbody targetRigidbody = colliders[i].GetComponent <Rigidbody> ();

            // If they don't have a rigidbody, go on to the next collider.
            if (!targetRigidbody)
            {
                continue;
            }

            // Add an explosion force.
            targetRigidbody.AddExplosionForce(m_ExplosionForce, transform.position, m_ExplosionRadius);

            // Find the ShipHealth script associated with the rigidbody.
            ShipHealth targetHealth = targetRigidbody.GetComponent <ShipHealth> ();

            // If there is no ShipHealth script attached to the gameobject, go on to the next collider.
            if (!targetHealth)
            {
                continue;
            }

            // Calculate the amount of damage the target should take based on it's distance from the shell.
            float damage = CalculateDamage(targetRigidbody.position);

            // Deal this damage to the Ship.
            targetHealth.TakeDamage(damage);
        }

        // Unparent the particles from the shell.
        m_ExplosionParticles.transform.parent = null;

        // Play the particle system.
        m_ExplosionParticles.Play();

        // Play the explosion sound effect.
        m_ExplosionAudio.Play();

        // Once the particles have finished, destroy the gameobject they are on.
        Destroy(m_ExplosionParticles.gameObject, m_ExplosionParticles.main.duration);
        // Destroy (Instantiate(m_ExplosionParticles), m_ExplosionParticles.main.duration);

        // Destroy the shell.
        Destroy(gameObject);
    }
Пример #7
0
 private void OnTriggerStay(Collider other)
 {
     if (other.tag == "Player")
     {
         audioSource.PlayOneShot(hitNoise, hitVolume);
         gameObject.transform.GetChild(0).gameObject.SetActive(false);
         gameObject.transform.GetChild(1).gameObject.SetActive(false);
         gameObject.transform.GetChild(2).gameObject.SetActive(false);
         thisCollider.isTrigger = false;
         Destroy(this.gameObject, 2f);
         shipHealth.TakeDamage(damage);
     }
 }
Пример #8
0
    void OnTriggerEnter(Collider other)
    {
        // Ignore if other is sibling
        if (other.tag == tag)
        {
            return;
        }

        // Enemy bullet
        if (other.tag.Contains(Tags.Bullet) && !other.tag.Contains(tag))
        {
            TakeDamage();
            other.transform.parent.gameObject.SetActive(false);
        }

        // Physical collision with ship
        ShipHealth otherHealth = other.transform.parent.GetComponentInChildren <ShipHealth>();

        if (otherHealth != null)
        {
            otherHealth.TakeDamage();
        }
    }
Пример #9
0
 public override void TakeDamage(int dmg)
 {
     hp.TakeDamage(dmg);
 }