Score.updateScore C# (CSharp) Method

updateScore() public method

public updateScore ( int toAdd ) : void
toAdd int
return void
    public void updateScore(int toAdd)
    {
        score += toAdd;
        GameObject.Find("Score").GetComponent<Text>().text = "Score: " + score.ToString();
    }

Usage Example

Example #1
0
    public GameObject nextPlayer;// Drag & Drop the prefab with the Ghost script attached to it
    void OnTriggerEnter(Collider other)
    {
        if (other.tag == "Egg")
        {
            scoreScript.updateScore();

            Destroy(other.gameObject); // Or whatever way you want to remove the coin.
            if (scoreScript.score == 1)
            {
                (Instantiate(FEggPrefab, Spawn.position, Spawn.rotation)).SetTarget(gameObject, 8);
            }
            else if (scoreScript.score == 2)
            {
                nextPlayer = GameObject.FindGameObjectsWithTag("Player")[1];
                (Instantiate(FEggPrefab, Spawn.position, Spawn.rotation)).SetTarget(nextPlayer, 8);
            }
            else
            {
                nextPlayer = GameObject.FindGameObjectsWithTag("Player")[2];
                (Instantiate(FEggPrefab, Spawn.position, Spawn.rotation)).SetTarget(nextPlayer, 8);
            }
        }
        else if (other.tag == "EndPoint")
        {
            PlayerPrefs.SetInt("TotalEggs", scoreScript.score + PlayerPrefs.GetInt("TotalEggs"));
            gameController.CompleteLevel();
        }
        else
        {
        }
    }
All Usage Examples Of Score::updateScore