Example #1
0
    void LateUpdate()
    {
        if (CurrentKey == KeyCode.None || FadingOut || Hopping)
        {
            return;
        }

        Ground closest      = null;
        float  bestDistance = Mathf.Infinity;

        // Only affect the ground of the tile you overlap with the most.
        foreach (var ground in CurrentGrounds)
        {
            var dist = Vector3.Distance(transform.position, ground.transform.position);

            // Lose
            if (ground.Dangerous)
            {
                Damage.Play();
                FadeOut("GameOver");
                return;
            }

            if (dist < bestDistance)
            {
                closest      = ground;
                bestDistance = dist;
            }
        }

        if (ScoreBox.LeavesRemaining == 0)
        {
            Happy.Play();
            Win.Play();
            Instantiate(PortalPrefab, transform.position, Quaternion.identity);
            FadeOut("MainGame");
        }
        else if (closest != null && !closest.Runed)
        {
            ScoreBox.Score += 10;
            ScoreBox.LeftRunes++;
            closest.ActivateRune();
        }
    }