Esempio n. 1
0
    void Start()
    {
        if (!players || !data || !currency)
        {
            Debug.LogErrorFormat("{0} of type {1} is missing core references to players, data and currency", this, this.GetType());
            return;
        }

        Player Human = players.GetHumanPlayer();
        Player Ai    = players.GetAiPlayer();

        if (!Human || !Human.Score)
        {
            Debug.LogErrorFormat("{0} of type {1} could not find an human player reference or its score field", this, this.GetType());
            return;
        }


        bool playerWon = (data.UseAI && Ai && Ai.Score) ? Human.Score.Value > Ai.Score.Value : Human.Score.Value > currency.BestScore;

        if (resultText)
        {
            if (data.UseAI)
            {
                resultText.text = playerWon ? WinText : LoseText;
            }
            else
            {
                resultText.text = playerWon ? WinTextSingle : LoseTextSingle;
            }
        }

        float finalScore = Human.Score.Value * data.ScoreRewardMultiplier;

        if (playerWon)
        {
            finalScore *= data.WinRewardMultiplier;
            if (victorySound)
            {
                victorySound.Play();
            }
            if (victoryEffect)
            {
                victoryEffect.Play(true);
            }
        }
        else
        {
            if (victoryEffect)
            {
                victoryEffect.Stop(true, ParticleSystemStopBehavior.StopEmitting);
            }
            if (defeatSound)
            {
                defeatSound.Play();
            }
        }

        currency.UpdateValues((int)finalScore, Human.Score.Value);

        if (rewardText.IsTextValid)
        {
            rewardText.Text = rewardText.Prefix + (int)finalScore + rewardText.Suffix;
        }
    }