Ejemplo n.º 1
0
    void OnDie()
    {
        // spawn a particle system when dying
        var vfx = Instantiate(deathVFX, deathVFXSpawnPoint.position, Quaternion.identity);

        Destroy(vfx, 5f);

        // tells the game flow manager to handle the enemy destuction
        m_EnemyManager.UnregisterEnemy(this);

        // loot an object
        if (TryDropItem())
        {
            Instantiate(lootPrefab, transform.position, Quaternion.identity);
        }

        var source = m_Health.LastDamageSource;

        if (source != null)
        {
            var player = source.GetComponent <PlayerWeaponsManager>();
            TelemetryLogger.LogEnemyKill(name, transform.position, player.GetActiveWeapon().weaponName, source.transform.position);
        }

        // this will call the OnDestroy function
        Destroy(gameObject, deathDuration);
    }