Example #1
0
    private void TakeHit(MakeDamage damageMaker, Transform other)
    {
        if (isDead)
        {
            return;
        }

        int resistance = stats.Defence;

        if (isPlayer)
        {
            Stuff head  = playerEquipement.head;
            Stuff torso = playerEquipement.torso;
            Stuff boots = playerEquipement.boots;

            if (head != null)
            {
                resistance += head.GetComponent <Stats>().Defence;
            }
            if (torso != null)
            {
                resistance += torso.GetComponent <Stats>().Defence;
            }
            if (boots != null)
            {
                resistance += boots.GetComponent <Stats>().Defence;
            }
        }

        stats.Life = damageMaker.isKiller ? 0 : Mathf.Max(0, stats.Life - (damageMaker.damage - resistance));

        currentHealth = stats.Life;

        if (!isPlayer)
        {
            LifeHud.GetComponent <LifeHud>().SetLife((float)stats.Life / (float)stats.MaxLife);
        }
        else
        {
            PlayerLifeHud.SetLife(stats.MaxLife, stats.Life);
        }

        if (Hit != null)
        {
            Hit(other);
        }

        if (currentHealth == 0)
        {
            isDead = true;
            if (!isPlayer)
            {
                LifeHud.gameObject.SetActive(false);
            }
            if (Die != null)
            {
                Die();
            }
        }
    }
Example #2
0
    private void OnTriggerEnter2D(Collider2D other)
    {
        //Debug.Log(other.tag);
        //Debug.Log(other.name);
        if (other.CompareTag("Weapon") && damageCooldown <= 0)
        {
            damageCooldown = baseDamageCooldown;
            MakeDamage damageMaker = other.GetComponent <MakeDamage>();

            if (damageMaker == null)
            {
                Debug.LogWarningFormat("Missing MakeDamage on {0}", other.name);
                return;
            }

            TakeHit(damageMaker, other.transform);
            other.GetComponent <Collider2D>().enabled = false;

            if (damageMaker.isUnique)
            {
                Destroy(damageMaker.gameObject);
            }

            return;
        }
    }
Example #3
0
 // Use this for initialization
 void Start()
 {
     makeDamage        = GetComponent <MakeDamage>();
     _collider         = GetComponent <BoxCollider2D>();
     _collider.enabled = false;
     smallBaseCooldown = smallCooldown;
     bigBaseCooldown   = bigCooldown;
     smallCooldown     = 0;
     bigCooldown       = 0;
 }
Example #4
0
    private void Initialize(SizeGameObjects size = SizeGameObjects.Normal, float _speed = 3.0f)
    {
        Vector3    newScale = new Vector3();
        MakeDamage md       = GetComponent <MakeDamage>();

        switch (size)
        {
        case SizeGameObjects.Small:
            newScale.Set(0.4f, 0.4f, 0.4f);
            md.damage = DataGame.baseUnit / 2f;
            break;

        case SizeGameObjects.Normal:
            newScale.Set(0.7f, 0.7f, 0.7f);
            md.damage            = DataGame.baseUnit;
            lifeAsteroid.reward *= 2;
            break;

        case SizeGameObjects.Large:
            newScale.Set(1.1f, 1.1f, 1.1f);
            md.damage            = DataGame.baseUnit * 2f;
            lifeAsteroid.reward *= 3;
            break;
        }

        transform.localScale = newScale;

        GetComponent <MovementEnemy>().verticalSpeed = _speed;

        lifeAsteroid.strength = DataGame.baseUnit * (int)size;

        // Определяем направление и скорость вращения
        int test = Random.Range(-4, 5);

        if (test == 0)
        {
            test = 1;
        }
        GetComponent <UnitRotation>().rotationDelta = test;
    }
Example #5
0
 private void Start()
 {
     killThis = GetComponent <DestroyBullet>();
     mDamage  = GetComponent <MakeDamage>();
 }