Exemplo n.º 1
0
 public void Checkup()
 {
     if (myDamage >= myStrength && null != myUnit)
     {
         myUnit.Death();
     }
 }
Exemplo n.º 2
0
    public IEnumerator GetDamage(UnitScript attacker, TileScript tile) // Gestione dell'attacco
    {
        if (!attacker.hasAttacked)
        {
            float  attackDistance = Vector2.Distance(transform.position, attacker.gameObject.transform.position);
            string distance       = attackDistance.ToString();

            if (!isInvulnerable)
            {
                if (attackDistance <= attacker.stats.attackRange && (!distance.Contains("2.5709") && !distance.Contains("2.9681") &&
                                                                     !distance.Contains("2.8906") && !distance.Contains("2.8653") && !distance.Contains("2.5317")))
                {
                    attacker.hasAttacked = true;

                    int tempDamage = attacker.stats.damage + attacker.bonusAttack;

                    attacker.gameObject.transform.DOShakePosition(shakeDuration, shakeStrenght, shakeVibrato, 90, false, true);
                    yield return(StartCoroutine(unitAnimationScript.PlayAttackAnimation(attacker.roleIndex, false, false)));

                    if (tempDamage > bonusDefense)
                    {
                        if (!soundsAudioSource.isPlaying)
                        {
                            soundsAudioSource.Stop();
                            if (attacker.roleIndex == 0)
                            {
                                soundsAudioSource.clip = attackAndMovementSoundEffects[0];
                            }
                            else if (attacker.roleIndex == 1)
                            {
                                soundsAudioSource.clip = attackAndMovementSoundEffects[1];
                            }
                            else if (attacker.roleIndex == 2)
                            {
                                soundsAudioSource.clip = attackAndMovementSoundEffects[2];
                            }
                            else if (attacker.roleIndex == 3)
                            {
                                soundsAudioSource.clip = attackAndMovementSoundEffects[3];
                            }
                            else if (attacker.roleIndex == 4)
                            {
                                soundsAudioSource.clip = attackAndMovementSoundEffects[4];
                            }
                            else if (attacker.roleIndex == 5)
                            {
                                soundsAudioSource.clip = attackAndMovementSoundEffects[5];
                            }
                            else if (attacker.roleIndex == 6)
                            {
                                soundsAudioSource.clip = attackAndMovementSoundEffects[6];
                            }

                            soundsAudioSource.Play();
                        }

                        tempDamage   -= bonusDefense;
                        stats.health -= tempDamage;

                        if (tempDamage > 0)
                        {
                            transform.DOShakePosition(shakeDuration / 2f, shakeStrenght / 1.5f, shakeVibrato / 1, 90, false, true);
                        }

                        if (isReadyToCounterAttack)
                        {
                            attacker.stats.health -= 3;

                            if (attacker.stats.health <= 0)
                            {
                                unitAnimationScript.PlayDeathAnimation();
                                attacker.Death();
                            }
                        }

                        if (stats.health <= 0)
                        {
                            unitAnimationScript.PlayDeathAnimation();
                            Death();
                        }
                    }
                    else
                    {
                        soundsAudioSource.clip = attackAndMovementSoundEffects[8];
                        soundsAudioSource.Play();
                    }

                    unitStatsTextScript.DoShakeDefenseBonus();

                    attacker.hasAttacked      = true;
                    attacker.currentMoveCount = 0;

                    DeselectUnitsAfterAttack();
                }
            }
        }
    }