Example #1
0
    void Update()
    {
        if (_playerTransform.position.y > _nextHeight)
        {
            _lastHeight = _nextHeight;
            NextGoal();
            GameController.Instance.PlaySound(GameSettings.Instance.AudioSettings.Milestone, 1.5f);
            _scorePitch = 1f;
        }

        // Set next goal text
        float scaleFactor = Mathf.Abs(Mathf.Cos(Time.timeSinceLevelLoad * 4.0f) * 0.5f);

        _line.SetWidth(scaleFactor, scaleFactor);
        GoalText.text = string.Format("Next Goal: {0}m", Mathf.Floor(_nextHeight - _playerTransform.position.y));

        // Add new enemies
        if (_playerTransform.position.y > _maxHeight)
        {
            _deltaPosition += _playerTransform.position.y - _maxHeight;
            if (_deltaPosition > ADD_ENTITY_DISTANCE)
            {
                Vector2 entityPosition = _playerTransform.position;

                entityPosition.x  = Random.Range(WorldUtils.GetLeftEdge() + 1f, WorldUtils.GetRightEdge() - 1f);
                entityPosition.y += 10f;

                GameObject entity = GameSettings.Instance.Prefabs.Enemy;

                if (Random.value < 0.85f)
                {
                    entity = GameSettings.Instance.Prefabs.Enemy;
                }
                if (Random.value < 0.25f)
                {
                    entity = GameSettings.Instance.Prefabs.Barrel;
                }

                Instantiate(entity, entityPosition, Quaternion.identity);

                _deltaPosition -= ADD_ENTITY_DISTANCE;
            }

            _maxHeight = Mathf.Max(0f, _playerTransform.position.y);

            // Update height score
            int score = (int)Mathf.Floor(_maxHeight / 2.5f);
            if (score > _scoreValue)
            {
                _scoreValue    = score;
                ScoreText.text = string.Format("{0}m", score);
                StartCoroutine(EmphasizeScore_Coroutine(0.25f));
                _scorePitch = (_playerTransform.position.y - _lastHeight) / (_nextHeight - _lastHeight) + 1f * 0.5f;
                GameController.Instance.PlaySound(GameSettings.Instance.AudioSettings.ScorePoint, 0.25f, _scorePitch);
            }
        }
    }
Example #2
0
    public void NextGoal()
    {
        ++_count;
        _nextHeight = _playerTransform.position.y + _addition * (_count * _multiplier);
        if (_line)
        {
            _line.SetWidth(0.2f, 0.2f);
            _line.SetColors(Color.gray, Color.gray);
            StartCoroutine(SlowMotion_Coroutine(0.25f));
            GameController.Instance.Camera.ShowStatus();
        }

        _line          = new GameObject("Line").AddComponent <LineRenderer>();
        _line.material = new Material(Shader.Find("Sprites/Default"));
        Color randomColor = new Color(0f, 1f, 0.7f);

        _line.SetColors(randomColor, randomColor);
        _line.SetWidth(0.2f, 0.2f);

        _line.SetPosition(0, new Vector3(WorldUtils.GetLeftEdge(), _nextHeight, 0));
        _line.SetPosition(1, new Vector3(WorldUtils.GetRightEdge(), _nextHeight, 0));
    }