Beispiel #1
0
    private void FixedUpdate()
    {
        if (!started)
        {
            return;
        }

        if (wait)
        {
            //Debug.Log("Waiting to start spawning");
            if (Time.fixedTime - waitingStarted > currentBatch.waitTime)
            {
                wait = false;
            }
        }
        else if (enemiesSpawned < currentBatch.enemyCount)
        {
            //Debug.Log("Spawning now " + Time.fixedTime);
            if (Time.fixedTime - lastSpawned > currentBatch.spawnTime)
            {
                GameObject      enemy = pool.ActivateObject(spawnPoint.position);
                EnemyNavigation nav   = enemy.GetComponent <EnemyNavigation>();
                Goblin          gob   = enemy.GetComponent <Goblin>();

                if (nav != null)
                {
                    nav.SetTarget(baseTower);
                }

                if (gob != null)
                {
                    gob.Initialize();
                }

                lastSpawned = Time.fixedTime;
                enemiesSpawned++;
            }
        }
        else
        {
            currentBatchIndex++;
            if (wave.batches.Count > currentBatchIndex)
            {
                currentBatch = wave.batches[currentBatchIndex];
                GameObject prefab = enemyConfig.Enemies.Where(x => x.type == currentBatch.enemyType).First().prefab;
                pool           = ObjectPooler.GetPool(prefab);
                wait           = true;
                waitingStarted = Time.fixedTime;
                enemiesSpawned = 0;
            }
            else
            {
                started = false;
            }
        }
    }
Beispiel #2
0
    void Update()
    {
        if (target != null && !dying)
        {
            Vector3 targetPos = target.transform.position;

            if (!target.IsAlive())
            {
                targetPos = previousTargetPos;
            }

            targetPos.y = 0.5f;

            var targetDir  = (targetPos - transform.position).normalized;
            var targetDist = Vector3.Distance(transform.position, targetPos);

            if (targetDist < energyTypeConfig.Speed * Time.deltaTime)
            {
                transform.position = targetPos;
            }
            else
            {
                transform.position = transform.position + targetDir * energyTypeConfig.Speed * Time.deltaTime;
            }

            if (Vector3.Distance(transform.position, targetPos) < minDistance)
            {
                if (energyTypeConfig.ExplodeRange > 0) //projectile is aoe, find targets
                {
                    doAoEDamage();
                }
                else
                {
                    target.TakeDamage(energyTypeConfig);
                }

                if (explosion != null)
                {
                    try
                    {
                        OneShotEffect expl = ObjectPooler.GetPool(explosion).ActivateObject(transform.position).GetComponent <OneShotEffect>();

                        expl.Play();
                    }
                    catch (Exception e)
                    {
                        Debug.Log("PASKA LÄSÄHTI!");
                        Debug.Log("Type: " + energyTypeConfig.Type);
                        Debug.Log("Explosion: " + explosion);
                        Debug.Log("Transform pos: " + transform.position);
                        Pool debugPool = ObjectPooler.GetPool(explosion);
                        Debug.Log("Pool: " + debugPool);
                        GameObject debugObj = debugPool.ActivateObject(transform.position);
                        Debug.Log("Test activating obj: " + debugObj);
                        OneShotEffect effect = debugObj.GetComponent <OneShotEffect>();
                        Debug.Log("Test getting OneShotEffect component: " + effect);
                        throw e;
                    }
                }
                targetsHit.Add(target.gameObject);

                if (!TryBounce())
                {
                    Invoke("Die", 0.5f);
                    StopEffects();
                    dying = true;
                }
            }

            previousTargetPos = targetPos;
        }
    }