public void StartEnemy(WaveConfig waveConfig) { _enemyClass = waveConfig.EnemyClass; _transform.localScale = waveConfig.EnemyClass.Size; _spriteRenderer.sprite = waveConfig.EnemyClass.Sprite; _enemyPathing.StartEnemyPathing(waveConfig.WaveWayPoints, waveConfig.MoveSpeed, gameObject, Destroy); _enemyShooting.StartEnemyShooting(_enemyClass, gameObject); _enemyHealth.StartEnemyHealth(gameObject, _enemyClass.MaxHealth, Death); }
private static void Shoot(EnemyClass enemyClass, GameObject gameObject, Vector3 shootingSoundPosition) { var position = gameObject.transform.position; var laser = ObjectPooler.SpawnFromPool(enemyClass.ShootPrefabTag, new Vector2(position.x, position.y - 1), Quaternion.identity); laser.GetComponent <Rigidbody2D>().velocity = new Vector2(0, -enemyClass.ShootSpeed); AudioSource.PlayClipAtPoint(enemyClass.ShootingSound, shootingSoundPosition, Random.Range(enemyClass.ShootingVolume.x, enemyClass.ShootingVolume.y)); }
public void StartEnemyShooting(EnemyClass enemyClass, GameObject gameObject) { var shotCounter = Random.Range(enemyClass.TimeBetweenShoots.x, enemyClass.TimeBetweenShoots.y); gameObject.UpdateAsObservable() .Sample(TimeSpan.FromSeconds(shotCounter)) .Subscribe(_ => Shoot(enemyClass, gameObject, Camera.main.transform.position)) .AddTo(_disposables); gameObject.OnDisableAsObservable() .Subscribe(_ => _disposables.Clear()); }
private static bool HeroHasMana(Hero hero, MethodInfo ability, EnemyClass enemy = null) { int currentMana = hero.mana; //Check if the hero has mana for the ability if(enemy == null) { ability.Invoke(hero, null); } else { ability.Invoke(hero, new object[] { enemy }); } if (hero.mana < 0 && hero.mana >= -100) { Console.WriteLine("No mana for that ability"); return false; } else if(hero.mana < - 100) { Console.WriteLine("Need a higher level to use that ability"); return false; } hero.mana = currentMana; return true; }
private static bool HeroHasMana(Hero hero, MethodInfo ability, EnemyClass enemy = null) { int currentMana = (int)hero.mana; //Check if the hero has mana for the ability if (enemy == null) //If there is no enemy the ability is a void { ability.Invoke(hero, null); } else { ability.Invoke(hero, new object[] { enemy }); } if (hero.mana < 0 && hero.mana >= -100) // If after being invoked the hero's mana is between 0 and -100 he doesn't have the mana for the ability { GameConsole.currentLog.Append("No mana for that ability \n"); hero.mana = currentMana; return false; } else if (hero.mana < -100)// If after being invoked the hero's level is not enough for the ability he loses 1000 mana temporarily { GameConsole.currentLog.Append("Need a higher level to use that ability \n"); hero.mana = currentMana; return false; } hero.mana = currentMana; return true; }