示例#1
0
    void Shoot()
    {
        Vector2      mousePosition     = new Vector2(Camera.main.ScreenToWorldPoint(Input.mousePosition).x, Camera.main.ScreenToWorldPoint(Input.mousePosition).y);
        Vector2      firePointPosition = new Vector2(firePoint.position.x, firePoint.position.y);
        RaycastHit2D hit = Physics2D.Raycast(firePointPosition, mousePosition - firePointPosition, 100, whatToHit);

        Effect();

        // Debug.DrawLine(firePointPosition, (mousePosition-firePointPosition)*100,Color.cyan);
        if (hit.collider != null)
        {
            Debug.Log(hit.collider.tag);

            if (hit.collider.tag == "Generic")
            {
                EnemyHealthSystem enemyHealthScript = hit.transform.GetComponent <EnemyHealthSystem>();
                enemyHealthScript.DeductHealth(Damage);
            }


            // Debug.DrawLine(firePointPosition, hit.point, Color.red);
        }
        else
        {
            Debug.Log("miss");
        }
    }
    public virtual void Shoot()
    {
        currentAmmo--;
        RaycastHit hit;

        flash.Play();
        AudioManager.instance.Play(shotSoundName, gameObject.transform.position, true, currentAmmo);
        playerNoiseManager.isEnemyHearingShoot(shotSoundIntensity);

        // Debug.Log(shotSoundName);

        // Ignore the Player layer, so we get the mask and then it is inverted
        int playerLayerMask = ~LayerMask.GetMask("Player");

        if (Physics.Raycast(currentCamera.transform.position, currentCamera.transform.forward, out hit, range, playerLayerMask))
        {
            // Debug.Log(hit.transform.name);
            GameObject impact;
            if (hit.transform.tag == "Enemy")
            {
                EnemyHealthSystem target = hit.transform.GetComponent <EnemyHealthSystem>();
                target.TakeDamage(damage);
                impact = Instantiate(impactEffectEnemy, hit.point, Quaternion.LookRotation(hit.normal));
            }
            else
            {
                impact = Instantiate(impactEffectSurface, hit.point, Quaternion.LookRotation(hit.normal));
            }
            Destroy(impact, 1.5f);
        }
    }
示例#3
0
 private void OnTriggerEnter2D(Collider2D collision)
 {
     if (collision.CompareTag("Enemy"))
     {
         EnemyHealthSystem hs = collision.GetComponent <EnemyHealthSystem>();
         if (hs)
         {
             hs.SetDamage(meleeDamage);
         }
     }
     else if (collision.CompareTag("Boss"))
     {
         BossHealthSystem bs = collision.GetComponent <BossHealthSystem>();
         if (bs)
         {
             bs.SetDamage(meleeDamage);
         }
     }
     else if (collision.CompareTag("Enemy"))
     {
         EnemyMeleeHealthSystem hms = collision.GetComponent <EnemyMeleeHealthSystem>();
         if (hms)
         {
             hms.SetDamage(meleeDamage);
         }
     }
 }
示例#4
0
    // Used by the gameManager to set up this enemy.
    public void Setup(GameManager gameManager, int sortOrder)
    {
        this.gameManager = gameManager;

        enemyAnimator = GetComponent <EnemyAnimator>();
        healthSystem  = GetComponent <EnemyHealthSystem>();

        enemyAnimator.SetSortingOrder(sortOrder);
        healthSystem.SetSortingOrder(sortOrder);
    }
示例#5
0
    // Spawn an enemy using the spawn system
    void Spawn()
    {
        // Get enemy
        GameObject enemy = enemy1; // Default enemy type

        if (spawn.enemyType == 1)
        {
            enemy = enemy2;
        }
        else if (spawn.enemyType == 2)
        {
            enemy = enemy3;
        }
        else if (spawn.enemyType == 3)
        {
            enemy = enemy4;
        }
        else if (spawn.enemyType == 4)
        {
            enemy = boss1;
        }

        if (spawn.pathChoice == 0)
        {
            enemy = InstantiateGameObject(enemy, spawn1);
        }
        else
        {
            enemy = InstantiateGameObject(enemy, spawn2);
        }

        enemy.GetComponent <EnemyController>().Setup(this, spawnSortOrder);

        spawnSortOrder += spawnSortOrderIncrement;

        if (spawnSortOrder > maxSpawnSortOrder)
        {
            spawnSortOrder = defaultSpawnSortOrder;
        }

        if (enemy.GetComponent <EnemyHealthSystem>().IsBoss())
        {
            bossHealth = enemy.GetComponent <EnemyHealthSystem>();
            bossHealth.Setup(hud);
            hud.ShowBossHealth(bossHealth.GetMaxHealth());
            Shake(1.0f);
        }
        else
        {
            enemy.GetComponent <EnemyHealthSystem>().Setup();
        }

        enemies.Add(enemy);
    }
示例#6
0
    private void OnTriggerEnter2D(Collider2D hitInfo)
    {
        EnemyHealthSystem enemy = hitInfo.GetComponent <EnemyHealthSystem>();

        if (enemy != null)
        {
            enemy.TakeDamageRanged(MBDamage);
        }
        if (hitInfo.tag == "Enemy" || hitInfo.tag == "Ground")
        {
            Destroy(gameObject);
        }
    }
示例#7
0
    public void Setup(EnemyHealthSystem enemyHealthSystem, float damage, float damageInterval, float damageDuration)
    {
        rend = GetComponent <SpriteRenderer>();

        this.enemyHealthSystem = enemyHealthSystem;
        this.damage            = damage;
        this.damageInterval    = damageInterval;

        hasDamageOverTime = damageInterval > 0;

        lifespan = damageDuration;
        Invoke("StartDestroy", lifespan);

        damageReadyTime = Time.timeSinceLevelLoad + this.damageInterval;
    }
示例#8
0
    public bool DestroyThisGameObject = true; //Destruir las balas

    //Compara tag enemy para aplicar daño
    private void OnTriggerEnter2D(Collider2D collision)
    {
        if (collision.CompareTag("Enemy"))
        {
            EnemyHealthSystem hs = collision.GetComponent <EnemyHealthSystem>();
            if (hs)
            {
                hs.SetDamage(Damage);

                if (DestroyThisGameObject)
                {
                    Destroy(gameObject);
                }
            }
            //Compara tag boss para aplicar daño
        }
        else if (collision.CompareTag("Boss"))
        {
            BossHealthSystem bs = collision.GetComponent <BossHealthSystem>();
            if (bs)
            {
                bs.SetDamage(Damage);

                if (DestroyThisGameObject)
                {
                    Destroy(gameObject);
                }
            }
        }
        //Compara tag enemymelee para aplicar daño
        else if (collision.CompareTag("EnemyMelee"))
        {
            EnemyMeleeHealthSystem hms = collision.GetComponent <EnemyMeleeHealthSystem>();
            if (hms)
            {
                hms.SetDamage(Damage);

                if (DestroyThisGameObject)
                {
                    Destroy(gameObject);
                }
            }
        }
    }