コード例 #1
0
        private void HandleDown()
        {
            //  If shot is cooling down return
            if (!canShoot)
            {
                return;
            }

            // If the game isn't playing don't do anything.
            if (!m_ShootingGalleryController.IsPlaying)
            {
                return;
            }

            //  If gun is empty reload and return
            if (currAmmo <= 0)
            {
                reloadSlider.SetActive(true);
                return;
            }
            bulletUpdate.UpdateDisplay(currAmmo);
            currAmmo -= 1;
            StartCoroutine(ShootCooldown());

            // Otherwise, if there is an interactible currently being looked at, try to find it's BabushkaTarget component.
            BabushkaTarget babushkaTarget = m_EyeRaycaster.CurrentInteractible ? m_EyeRaycaster.CurrentInteractible.GetComponent <BabushkaTarget>() : null;

            // We will also get the transform of the target for the purpose of calculating distance
            Transform target;
            float     targetDistance;

            // If we discovered a babushkaTarget a moment ago...
            if (babushkaTarget)
            {
                target         = babushkaTarget.transform;
                targetDistance = Vector3.Distance(m_GunEnd.position, target.position);
            }
            else
            {
                target         = null;
                targetDistance = m_DefaultLineLength;
            }

            // If there is a BabushkaTarget component tell it to receive a hit
            if (babushkaTarget)
            {
                babushkaTarget.ReceiveHit(scoreMultiplier, (int)targetDistance);
                scoreMultiplier += 1;
            }
            //  Otherwise the player has missed. Reset their multiplier.
            else
            {
                scoreMultiplier = 1;
            }
            UpdateScoreMultiplierDisplay();

            // Display visual aspects of shot
            StartCoroutine(Fire(target, targetDistance));
        }
コード例 #2
0
        private void HandleTargetRemoved(/*ShootingTarget target*/ BabushkaTarget target)
        {
            // Now that the event has been hit, unsubscribe from it.
            target.OnRemove -= HandleTargetRemoved;

            // Return the target to it's object pool.
            // m_TargetObjectPool.ReturnGameObjectToPool (target.gameObject);

            // Increase the likelihood of a spawn next time because there are fewer targets now.
            SetSpawnProbability(m_SpawnProbability + m_ProbabilityDelta);
        }
コード例 #3
0
        private IEnumerator PlayUpdate()
        {
            // When the updates start, the probability of a target spawning is 100%.
            SetSpawnProbability(1f);

            // The time remaining is the full length of the game length.
            float gameTimer = m_GameLength;

            // The amount of time before the next spawn is the full interval.
            float spawnTimer = m_SpawnInterval;

            // The amount of time before the difficulty notches up
            float difficultyTimer = m_DifficultyInterval;

            // While there is still time remaining...
            while (gameTimer > 0f)
            {
                // ... check if the timer for spawning has reached zero.
                if (spawnTimer <= 0f)
                {
                    // If it's time to spawn, check if a spawn should happen based on the probability.
                    if (Random.value < m_SpawnProbability)
                    {
                        // If a spawn should happen, restart the timer for spawning.
                        spawnTimer = m_SpawnInterval;

                        // Decrease the probability of a spawn next time because there are now more targets.
                        SetSpawnProbability(m_SpawnProbability - m_ProbabilityDelta);

                        int            randomSpawnerIndex = Random.Range(0, spawners.transform.childCount);
                        BabushkaTarget targetScript       = spawners.transform.GetChild(randomSpawnerIndex).gameObject.GetComponent <Spawner>().Spawn();
                        if (targetScript)
                        {
                            targetScript.OnRemove += HandleTargetRemoved;
                        }
                        // Spawn a target.
                        // Spawn (gameTimer);
                    }
                }
                // When the difficulty timer has gone off:
                if (difficultyTimer <= 0f)
                {
                    // Reset it, then notch up the difficulty and recalculate the probability delta.
                    difficultyTimer      = m_DifficultyInterval;
                    m_IdealTargetNumber += 1;
                    m_ProbabilityDelta   = (1f - m_BaseSpawnProbability) / m_IdealTargetNumber;
                    SetSpawnProbability(1f);
                    Debug.Log("Ideal targets number: " + m_IdealTargetNumber + ". Probability delta: " + m_ProbabilityDelta);
                }

                // Wait for the next frame.
                yield return(null);

                // Decrease the timers by the time that was waited.
                gameTimer       -= Time.deltaTime;
                spawnTimer      -= Time.deltaTime;
                difficultyTimer -= Time.deltaTime;

                // Set the timer bar to be filled by the amount
                m_TimerBar.fillAmount = gameTimer / m_GameLength;
            }
        }