private void Update() { if (Connected) { firingTimer += Time.deltaTime; if (firingTimer > firingInterval) { firingTimer = 0f; if (currentTarget == null || !currentTarget.IsAlive() || TargetDistance(currentTarget.gameObject) > maxDistance) { currentTarget = GetNextTarget(); } if (currentTarget != null) { FireAtCurrentTarget(); } } } }
void Update() { if (currentWaveIndex == waves.Count - 1 && phase != SpawnPhase.Spawning) { bool finished = true; foreach (var go in GameObject.FindGameObjectsWithTag("Goblin")) { Goblin goblin = go.GetComponent <Goblin>(); if (goblin.IsAlive()) { finished = false; break; } } if (finished) { UIManager.main.ShowTheEnd(); } } if (currentWaveIndex == waves.Count - 1) { UIManager.main.HideIntermissionInfo(); UIManager.main.HideIntermissionTimer(); } if (phase == SpawnPhase.Spawning) { //Debug.Log("Starting to spawn " + Time.fixedTime); if (!spawningOnGoing) { for (int i = 0; i < 4; i++) { WaveSpawn wave = currentWave.GetSpawn(i); //Batch batch = currentBatch[i]; if (wave.batches.Count > 0) { spawnPoints[i].SetWaveSpawn(wave); } } spawningOnGoing = true; } // next wave when all the spawners have spawned their enemies if (spawnPoints.Aggregate(true, (prod, next) => prod && next.GetHasEnded())) { spawningOnGoing = false; phase = SpawnPhase.Waiting; waitStarted = Time.fixedTime; } } else if (phase == SpawnPhase.Waiting && (Time.fixedTime - waitStarted > currentWave.WaveEndWaitTime)) { phase = SpawnPhase.Ended; UIManager.main.HideIntermissionInfo(); } else if (phase == SpawnPhase.Waiting) { if (Input.GetKeyDown(KeyCode.Space) && TutorialManager.main.GetFinished()) { skipWaveWaitingPeriod(); UIManager.main.HideIntermissionInfo(); } else { UIManager.main.UpdateIntermissionInfo("Wave " + (currentWaveIndex + 2) + " spawns in:"); UIManager.main.UpdateIntermissionTimer(currentWave.WaveEndWaitTime - (Time.fixedTime - waitStarted)); } } else if (phase == SpawnPhase.Ended) { waveEndStuff(); } }
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; } }