private void Fire() { // checks the firerate and fires laser from objectpool. if (Time.time > m_nextFire) { m_nextFire = Time.time + FireRate; var ammunitionClone = PoolManager.SpawnObject(ammunitionPrefab); var ammuTransform = ammunitionClone.transform; ammuTransform.position = m_bulletSpawnTransform.position; ammuTransform.rotation = gameObject.transform.rotation; IShootable shootable = ammunitionClone.GetComponent <IShootable>(); shootable.Source = m_bulletSpawnTransform; AudioManager.Instance.PlaySFX(soundFXType); FireAmmunition(shootable, ShootSpeed); } }
public IEnumerator StartSpawner(Transform target) { if (stopSpawn) { yield return(null); } // Wait to Start Spawning yield return(new WaitForSeconds(startWaitTs)); m_currentEnemy = UnityEngine.Random.Range(0, m_enemyPrefabToSpawn.Length); m_currentEnemy = 0; var enemyClone = PoolManager.SpawnObject(m_enemyPrefabToSpawn[m_currentEnemy]); var activeEnemyUnity = enemyClone.GetComponent <ActiveEnemyUnit>(); // Suscribe to Enemy Collision Events - When is Shot BasicCollisionDectection collisionDetection = activeEnemyUnity.GetComponentInChildren <BasicCollisionDectection>(); if (collisionDetection != null) { collisionDetection.UnitShot += (s, e) => OnShot(s, e); } // Suscribe to Enemy Collision Events - When is Collided activeEnemyUnity.Collided += (s, e) => { m_spawnEnemies.Remove(activeEnemyUnity); }; if (m_spawnEnemies == null) { m_spawnEnemies = new List <ActiveEnemyUnit>(); } m_spawnEnemies.Add(activeEnemyUnity); // Spawn at free position activeEnemyUnity.Spawn(); // Start movement ICustomMove customMove = activeEnemyUnity.GetComponent <ICustomMove>(); customMove.Move(target); //activeEnemyUnity.Move(target); }
public void Explode(ExplosionType type, Vector3 position) { for (int i = 0; i < explosions.Length; i++) { BaseExplosion currentExplosion = explosions[i]; if (currentExplosion.ExplosionType == type) { var clone = PoolManager.SpawnObject(currentExplosion.ParticleSysPrefab); if (clone == null) { return; } ParticleSystem ps = clone.GetComponent <ParticleSystem>(); ps.transform.position = position; currentExplosion.ExplosionFinished += (s, e) => ExplosionDie(clone); currentExplosion.Explode(currentExplosion.SoundFX, ps, position); return; } } }
private void OnAsteroidShatter(object sender, EventArgs e) { PassiveEnemy passiveEnemy = sender as PassiveEnemy; passiveEnemy.AsteroidShatter -= OnAsteroidShatter; for (int i = 0; i < passiveEnemy.NumBits; i++) { var clone = PoolManager.SpawnObject(m_childPrefabToSpawn); var entity = clone.GetComponent <EntityBehaviour>(); entity.SpawnAt(passiveEnemy.transform.position); m_spawnObjects.Add(entity); BasicCollisionDectection collisionDetection = entity.GetComponentInChildren <BasicCollisionDectection>(); if (collisionDetection != null) { collisionDetection.UnitShot += (s, evt) => OnShot(s, evt); } // Suscribe to collision events entity.Collided += (s, evt) => { m_spawnObjects.Remove(entity); }; } }