コード例 #1
0
    private void SpawnEnemy()
    {
        GameObject newSpawnObj = ObjectPool.Instance.GetObject(spawnType.ToPoolObject());

        if (newSpawnObj)
        {
            newSpawnObj.transform.position = ActualSpawnPos;
            ISpawnable spawnable = newSpawnObj.GetComponentInChildren <ISpawnable>();
            if (!spawnable.HasWillBeenWritten())
            {
                spawnable.RegisterDeathEvent(ReportDeath);
            }

            EnemyBase enemyBase = newSpawnObj.GetComponent <EnemyBase>();

            if (enemyBase)
            {
                enemyBase.SpawnWithRagdoll(ActualSpawnPos);
            }

            EventSystem.Instance.TriggerEvent(Strings.Events.ENEMY_SPAWNED, newSpawnObj);
        }
        else
        {
            OnEnemyDeath();
            Debug.LogFormat("<color=#ffff00>" + "NOT ENOUGH SPAWN-OBJECTS for: " + spawnType + "</color>");
        }
    }
コード例 #2
0
    void SpawnEnemy(Vector3 spawnPosition, PoolObjectType enemy)
    {
        spawnPosition.y += spawnHeightOffset;
        GameObject spawnedObject = ObjectPool.Instance.GetObject(enemy);

        //spawnedObject.SetActive(false);

        if (spawnedObject)
        {
            spawnedObject.transform.position = spawnPosition;
            ISpawnable spawnable = spawnedObject.GetComponentInChildren <ISpawnable>();

            if (!spawnable.HasWillBeenWritten())
            {
                spawnable.RegisterDeathEvent(ReportDeath);
            }
            else
            {
                Debug.Log("No ReportDeath???");
            }

            EnemyBase enemyBase = spawnedObject.GetComponent <EnemyBase>();
            if (enemyBase)
            {
                enemyBase.SpawnWithRagdoll(spawnPosition);
            }

            EventSystem.Instance.TriggerEvent(Strings.Events.ENEMY_SPAWNED, spawnedObject);

//            Debug.Log("SPAWN: " + ++NumSpawn);

            currentNumEnemies++;
        }
        else
        {
            Debug.LogFormat("<color=#ffff00>" + "NOT ENOUGH SPAWN-OBJECT" + "</color>");
        }
    }