示例#1
0
    IEnumerator DeathAnimCoroutine(Enemy enemy)
    {
        if (!enemy.isDead)
        {
            enemy.canAttack = false;
            enemy.isDead    = true;
            if (enemy.GetComponent <LookAtPlayer>() != null)
            {
                enemy.GetComponent <LookAtPlayer>().canLookAt = false;
            }
            var     playerPos   = GameObject.Find("Player").transform.position;
            var     distance    = new Vector3(playerPos.x, enemy.gameObject.transform.position.y, playerPos.z) - enemy.gameObject.transform.position;
            Vector3 direction   = -distance.normalized * 2.5f;
            var     origin      = enemy.gameObject.transform.position;
            var     destination = origin + direction;
            var     speedRatio  = 10;
            while (enemy.gameObject.transform.position != destination)
            {
                enemy.transform.position = Vector3.Lerp(enemy.gameObject.transform.position, destination, 2f * speedRatio * (Time.deltaTime) * Config.TimeScale);
                speedRatio++;
                yield return(0);
            }
            yield return(new WaitForSeconds(0.01f));

            enemy.gameObject.SetActive(false);


            var go = GameObject.Instantiate(enemyParticle, enemy.gameObject.transform.position, Quaternion.identity);
            SFXManager.PlaySFX(SFXManager.Explosion, go.GetComponent <AudioSource>());
            go.AddComponent <ParticleStoper>();
            EnemyDeathEvent?.Invoke();
            enemy.setPositionInitialPOsition();
        }
    }
示例#2
0
 private void Die()
 {
     EnemyDeathEvent.Invoke(type);
     Destroy(gameObject);
     if (deathPrefab != null)
     {
         Instantiate(deathPrefab, transform.position, transform.rotation);
     }
 }
示例#3
0
    void Awake()
    {
        explosion = GetComponent <Explosion>();

        if (LevelManager.Instance != null)
        {
            this.EnemyDeathEvent.AddListener(LevelManager.Instance.OnEnemyDied);
            this.EnemySpawnEvent.AddListener(LevelManager.Instance.OnEnemySpawned);
        }

        EnemySpawnEvent.Invoke(type);
    }
示例#4
0
    public void KillMe()
    {
        GameManager.Instance.ScoreUp();
        explotion = PoolManager.GetInstance().CallByName("Explotion");
        explotion.transform.position = transform.position + new Vector3(0, 1, 0);
        Invoke(nameof(TurnOffExplotion), 2);

        onDeathEvent.Invoke(this);
        DeactivateTookDamage();
        health.RestoreHealth();
        PoolManager.GetInstance().TurnOffByName("Enemy", this.gameObject);
    }
示例#5
0
 public void TakeDamage(int damage)
 {
     if (alive)
     {
         hp -= damage;
         if (hp < 1)
         {
             alive = false;
             OnDeath.Invoke(this);
             animator.SetTrigger(animatorDeathTrigger);
         }
         else
         {
             StartCoroutine(DamageFlash());
         }
     }
 }
示例#6
0
    void ReallyDie()
    {
        if (!isReallyDead)
        {
            // manage event
            enemyDeathEvent.Invoke();

            // do not destroy because of time rewind, instead set inactive
            rb2d.Sleep();
            rb2d.gravityScale = 0;

            isReallyDead = true;

            // remove from event invokers
            EventManager.RemoveEnemyDeathInvoker(spawner, this);
            EventManager.RemoveEnemyResurrectInvoker(spawner, this);
        }
    }
示例#7
0
    protected void Dead( )
    {
        m_animator.SetBool("death", m_data.curLife <= 0);
        if (m_anmSttInfo.IsName("0.death"))
        {
            if (tag == "Enemy")
            {
                tag = "dead";
            }
            if (m_anmSttInfo.normalizedTime > 0.9f)
            {
                transform.position = Vector3.zero;
                m_hasInited        = false;
                if (hpBar)
                {
                    PoolManager.GetInstance().GetPool(hpBar.name).GivebackObject(hpBar);
                }
                for (int i = 1; i < transform.childCount; i++)
                {
                    if (transform.GetChild(i).gameObject.activeSelf)
                    {
                        PoolManager.GetInstance().GetPool(transform.GetChild(i).name).GivebackObject(transform.GetChild(i));
                    }
                    else
                    {
                        transform.GetChild(i).parent = null;
                    }
                }
                PoolManager.GetInstance().GetPool(gameObject.name).GivebackObject(gameObject);

                // some quests will listen this enemy death event
                // now we sent a event to these listener
                enemyDeathEvent.Invoke((byte)enemyId);
            }
        }
        if (tag == "dead")
        {
            return;
        }
    }
示例#8
0
 static public void RaiseOnEnemyDeath(DeathEventArguments args)
 {
     OnEnemyDeath?.Invoke(args);
 }
示例#9
0
 void OnDeathEvent()
 {
     OnDeath.Invoke(this);
     Destroy(gameObject.transform.parent.gameObject);
 }