Example #1
0
    /// <summary>
    /// Takes the damage.
    /// </summary>
    /// <param name="damage">Damage.</param>
    void ILaserable.TakeDamage(int damage)
    {
        //Remove hitpoints as needed
        Hitpoints -= damage;

        //Blend the materials to make it take damage
        _renderer.material.SetFloat("_Blend", 1);

        //Destroy if it's health is below zero
        if (Hitpoints <= 0)
        {
            //Add time to prevent laser firing while we die.
            _laserShotTimer = 99f;

            if (mySpawner)
            {
                mySpawner.ClearDrone();
            }
            if (ExplosionPrefab)
            {
                Instantiate(ExplosionPrefab, transform.position, Quaternion.identity);
            }

            if (_audioSource != null && clips.Length > 1)
            {
                _audioSource.Stop();
                _audioSource.clip   = clips[1];
                _audioSource.volume = 1f;
                _audioSource.Play();
            }

            StartCoroutine(DestroyDrone());
            return;
        }
    }