Exemple #1
0
 private void SetupTimers()
 {
     ShootTimer = gameObject.AddComponent <IntervalTimerComponent>();
     ShootTimer.SetInterval(SHOOT_COOLDOWN);
     ShootTimer.IsActive  = true;
     ShootTimer.AutoReset = false;
 }
Exemple #2
0
 private void SetupDashTimer()
 {
     dashTimer = gameObject.AddComponent <IntervalTimerComponent>();
     dashTimer.SetInterval(CooldownTime);
     dashTimer.AutoReset = false;
     dashTimer.OnIntervalReached.AddListener(OnIntervalReached);
 }
Exemple #3
0
        public override void ComponentStart()
        {
            var brain = GetRequiredComponent <HumanoidNPCBrainComponent>();

            brain.attackByPlayer.AddListener(OnAttackedByPlayer);
            brain.attackBegin.AddListener(OnAttackBegin);
            brain.attackEnd.AddListener(OnAttackEnd);
            brain.damageEnable.AddListener(OnDamageEnable);
            brain.damageDisable.AddListener(OnDamageDisable);

            var brainTimerPrefabTemp = new GameObject();

            brainTimerPrefabTemp.AddComponent <IntervalTimerComponent>();
            var inst = Instantiate(brainTimerPrefabTemp, transform);

            inst.name = "BrainTimer";

            brainTimer       = GetRequiredComponent <IntervalTimerComponent>(inst);
            brainTimer.Label = "BrainTimerComponent";
            brainTimer.SetInterval((int)UnityEngine.Random.Range(thinkTimeMin, thinkTimeMax));
            brainTimer.SelfDestruct = false;
            brainTimer.Randomize    = false;
            brainTimer.AutoReset    = true;
            brainTimer.OnIntervalReached.AddListener(BrainUpdate);

            Destroy(brainTimerPrefabTemp);
            base.ComponentStart();
        }
        public void PhaseBegin(ILevelContext context)
        {
            flyingVFormationPrefab = ComponentBase.GetRequiredResource <GameObject>($"{ResourcePaths.PrefabsFolder}/Actors/Formations/{GameObjects.Formations.FlyingV}");

            GameObject asteroidPrefab = ComponentBase.GetRequiredResource <GameObject>($"{ResourcePaths.PrefabsFolder}/Projectiles/{GameObjects.Projectiles.Asteroid}");

            // Create an asteroid spawner which will generate a random asteroid ever buncha milliseconds
            asteroidSpawner = ComponentBase.InstantiateInLevel("AsteroidSpawner", Vector3.zero, typeof(AutoSpawnerComponent));
            ComponentBase.GetRequiredComponent <AutoSpawnerComponent>(asteroidSpawner).Initialize(500, asteroidPrefab);

            // This method is used to spawn enemies, initialize the phase, etc
            GameObject enemy = ComponentBase.GetRequiredResource <GameObject>($"{ResourcePaths.PrefabsFolder}/Actors/Enemies/Shooter_AI");

            GameObject inst = ComponentBase.InstantiateInLevel(enemy);

            inst.transform.position = new Vector3(-2, 3f, 3);
            GameObject inst2 = ComponentBase.InstantiateInLevel(enemy);

            inst2.transform.position = new Vector3(2, 3, 4);

            // A formation will spawn after a while
            intervalTimerObject = new GameObject("FormationSpawnTimer");

            intervalTimerObject.AddComponent <IntervalTimerComponent>();
            IntervalTimerComponent timer = ComponentBase.GetRequiredComponent <IntervalTimerComponent>(intervalTimerObject);

            timer.SetInterval(3000);
            timer.OnIntervalReached.AddListener(SpawnFormation);
            timer.SelfDestruct = true;
            timer.IsActive     = true;

            // Play some dank tunes
            ComponentBase.GetMusicPlayer().Loop(MusicPlayerComponent.Song.Prototype);
        }
Exemple #5
0
 // Initialize and attach all Interval Timer Components
 private void CreateTimers()
 {
     shootTimer = gameObject.AddComponent <IntervalTimerComponent>();
     shootTimer.SetInterval(shotDelay);
     shootTimer.AutoReset = true;
     shootTimer.Randomize = true;
     shootTimer.OnIntervalReached.AddListener(ShotTimerReached);
     shootTimer.IsActive = true;
 }
Exemple #6
0
 private void CreateTimers()
 {
     lifeTimer = gameObject.AddComponent <IntervalTimerComponent>();
     lifeTimer.SetInterval(lifetime);
     lifeTimer.AutoReset = false;
     lifeTimer.Randomize = false;
     lifeTimer.IsActive  = true;
     lifeTimer.OnIntervalReached.AddListener(Die);
 }
 // Called from the interval timer
 private void BrainUpdate()
 {
     if (isActiveAndEnabled)
     {
         if (player.transform.position.x > transform.position.x || !IsFacingRight)
         {
             Attack();
         }
         brainTimer.SetInterval((int)UnityEngine.Random.Range(thinkTimeMin, thinkTimeMax));
     }
 }
        public override void ComponentStart()
        {
            if (!UnityUtils.Exists(bulletPrefab))
            {
                Debug.LogWarning($"No bullet prefab specified for {gameObject.name}!");
            }

            if (!Positions.Any())
            {
                Debug.LogError($"Enemy shooter named '{gameObject.name}' doesn't have any predefined positions and his behavior will not work right.");
            }

            var brain = GetRequiredComponent <HumanoidNPCBrainComponent>();

            if (!UnityUtils.Exists(brain))
            {
                throw new UnityException($"Unable to find a HumanoidNPCBrain on {gameObject.name}");
            }

            brain.attackByPlayer.AddListener(OnAttackedByPlayer);
            brain.attackBegin.AddListener(OnAttackBegin);
            brain.attackEnd.AddListener(OnAttackEnd);
            brain.damageEnable.AddListener(OnDamageEnable);
            brain.damageDisable.AddListener(OnDamageDisable);

            var brainTimerPrefabTemp = new GameObject();

            brainTimerPrefabTemp.AddComponent <IntervalTimerComponent>();
            var inst = Instantiate(brainTimerPrefabTemp, transform);

            inst.name = "BrainTimer";

            brainTimer       = GetRequiredComponent <IntervalTimerComponent>(inst);
            brainTimer.Label = "BrainTimerComponent";
            brainTimer.SetInterval((int)UnityEngine.Random.Range(thinkTimeMin, thinkTimeMax));
            brainTimer.SelfDestruct = false;
            brainTimer.Randomize    = false;
            brainTimer.AutoReset    = true;
            brainTimer.OnIntervalReached.AddListener(BrainUpdate);

            shooterAnimator = GetRequiredComponent <ShooterSkeletonAnimatorComponent>();

            if (!UnityUtils.Exists(shooterAnimator))
            {
                throw new UnityException($" {gameObject.name} requires a shooter skeleton animator and you don't have that.");
            }

            Destroy(brainTimerPrefabTemp);

            currentSeekedPosition = FindNearestShooterPosition();

            base.ComponentStart();
        }
        private void InitializeTimers()
        {
            shootTimer = gameObject.AddComponent <IntervalTimerComponent>();
            shootTimer.SetInterval(SHOOT_COOLDOWN);
            shootTimer.IsActive  = true;
            shootTimer.AutoReset = false;

            stunTimer = gameObject.AddComponent <IntervalTimerComponent>();
            stunTimer.SetInterval(STUN_COOLDOWN);
            stunTimer.IsActive  = false;
            stunTimer.AutoReset = false;
            stunTimer.OnIntervalReached.AddListener(OnStunTimerIntervalReached);
        }
Exemple #10
0
        // Called from the interval timer
        private void BrainUpdate()
        {
            if (isActiveAndEnabled)
            {
                if (!isAttacking && PlayerIsInRange())
                {
                    Attack();
                }

                UnityEngine.Random.InitState(DateTime.Now.Millisecond);
                brainTimer.SetInterval((int)UnityEngine.Random.Range(thinkTimeMin, thinkTimeMax));
            }
        }
        // Called from the interval timer
        private void BrainUpdate()
        {
            if (isActiveAndEnabled)
            {
                // if we're at our position, fire a bullet towards the player
                if (IsNearEnoughToPosition())
                {
                    Attack();
                }

                // Additionally, if the player is in our area, pick a new position
                if (player.transform.position.x.IsWithin(currentSeekedPosition.Range, currentSeekedPosition.Position.x))
                {
                    currentSeekedPosition = FindSecondNearestShooterPositionAwayFromPosition(player.transform.position.x);
                }

                brainTimer.SetInterval((int)UnityEngine.Random.Range(thinkTimeMin, thinkTimeMax));
            }
        }
        public void PhaseBegin(ILevelContext context)
        {
            GameObject asteroidPrefab = ComponentBase.GetRequiredResource <GameObject>($"{ResourcePaths.PrefabsFolder}/Projectiles/{GameObjects.Projectiles.Asteroid}");

            // Create an asteroid spawner which will generate a random asteroid every half second
            asteroidSpawner = ComponentBase.InstantiateInLevel("AsteroidSpawner", Vector3.zero, typeof(AutoSpawnerComponent));
            ComponentBase.GetRequiredComponent <AutoSpawnerComponent>(asteroidSpawner).Initialize(500, asteroidPrefab);


            // A formation will spawn after a while
            intervalTimerObject = new GameObject("FormationSpawnTimer");

            intervalTimerObject.AddComponent <IntervalTimerComponent>();
            IntervalTimerComponent timer = ComponentBase.GetRequiredComponent <IntervalTimerComponent>(intervalTimerObject);

            timer.SetInterval(15000); // 15 seconds
            timer.OnIntervalReached.AddListener(TimerDone);
            timer.SelfDestruct = true;
            timer.IsActive     = true;
        }
        public override void ComponentUpdate()
        {
            // Make sure index isn't out of bounds (can happen if manipulating values in inspector)
            index = Mathf.Min(index, instructions.Count() - 1);

            var currentInstruction = instructions[index];

            if (!timer.IsActive)
            {
                if (IsNearDestination(currentInstruction))
                {
                    timer.SetInterval(currentInstruction.WaitTime);
                    timer.IsActive = true;
                }
            }

            UpdateVelocity(currentInstruction);

            base.ComponentUpdate();
        }
        public override void ComponentStart()
        {
            if (!UnityUtils.Exists(bulletPrefab))
            {
                Debug.LogWarning($"No bullet prefab specified for {gameObject.name}!");
            }


            var brain = GetRequiredComponent <HumanoidNPCBrainComponent>();

            brain.attackBegin.AddListener(OnAttackBegin);
            brain.attackByPlayer.AddListener(OnAttackedByPlayer);

            var brainTimerPrefabTemp = new GameObject();

            brainTimerPrefabTemp.AddComponent <IntervalTimerComponent>();
            var inst = Instantiate(brainTimerPrefabTemp, transform);

            inst.name = "BrainTimer";

            brainTimer       = GetRequiredComponent <IntervalTimerComponent>(inst);
            brainTimer.Label = "BrainTimerComponent";
            brainTimer.SetInterval((int)UnityEngine.Random.Range(thinkTimeMin, thinkTimeMax));
            brainTimer.SelfDestruct = false;
            brainTimer.Randomize    = false;
            brainTimer.AutoReset    = true;
            brainTimer.OnIntervalReached.AddListener(BrainUpdate);

            shooterAnimator = GetRequiredComponent <ShooterSkeletonAnimatorComponent>();

            if (!IsFacingRight)
            {
                shooterAnimator.FaceTowardsPosition(transform.position.x - 1);
            }

            Destroy(brainTimerPrefabTemp);

            base.ComponentStart();
        }
 private void SetTimer(float millisecs)
 {
     timer.SetInterval(millisecs);
     timer.IsActive = true;
 }