Exemple #1
0
 protected virtual void OnCollisionEnter2D(Collision2D collision)
 {
     if (collision.gameObject.CompareTag("Ground"))
     {
         GameController.earnedMoney += Bonus;
         Destroy(gameObject);
     }
     else if (collision.gameObject.CompareTag("HeroBullet"))
     {
         HeroBullet bullet = collision.gameObject.GetComponent <HeroBullet>();
         Hp        -= bullet.damage;
         bullet.hp -= Damage;
         if (bullet.hp <= 0)
         {
             Destroy(bullet.gameObject);
         }
         if (Hp <= 0)
         {
             Destroy(gameObject);
         }
     }
     else if (collision.gameObject.CompareTag("Player"))
     {
         Destroy(gameObject);
     }
     if (collision.gameObject.CompareTag("Ground") || (collision.gameObject.CompareTag("Player") && Hero.Hp > 0) || collision.gameObject.CompareTag("HeroBullet"))
     {
         GameController.countEnemies--;
         if (GameController.countEnemies <= 0)
         {
             GameController.Finish();
         }
         GameController.mobsCompleted++;
     }
 }
Exemple #2
0
    public void Shooting(int kX, int kY)
    {
        GameObject obj  = Instantiate(bullet, transform.position, Quaternion.identity);
        HeroBullet bull = obj.GetComponent <HeroBullet>();

        bull.damage = Damage;
        bull.ChangeDirection(kX, kY);
    }
Exemple #3
0
    void Fire()
    {
        // Создаем снаряд в точке выстрела.
        HeroBullet Bull = Instantiate(_bullet, _shootPoint.position, _shootPoint.rotation);

        // Проверяем направление пушки.
        if (!IsForward)
        {
            // Пускаем снаряд в ту сторону.
            Bull._dir.x *= -1;
        }

        // При этом меняем направление скорости.
        Bull._speed *= Mathf.Sign(Bull._dir.x);
    }
    //public void Sword()
    //{
    //    _myAnim.SetTrigger("Attack2");

    //    Invoke("Fire2", 0.3f);
    //}

    // Метод дальней атаки.
    public void Fire1()
    {
        //_myAnim.SetTrigger("Attack1");

        // Создаем снаряд в точке выстрела.
        HeroBullet Bull = Instantiate(_bullet, _shootPoint.position, _shootPoint.rotation);

        // Проверяем направление персонажа.
        if (!IsForward)
        {
            // Пускаем снаряд в ту сторону.
            //Bull._dir.x *= -1;

            // При этом меняем направление скорости.
            Bull._speed *= Mathf.Sign(Bull._dir.x);
        }
    }