Working with scores – scripting with text

To display a score in the GUI, we'll first need score functionality, that is, code to create a score system. Essentially, the score functionality will be added to a general, overarching GameController class, responsible for all game-wide logic and features. The code for GameController and its score feature set is included in Code Sample 4.4, as follows. This file should be added to the Scripts folder of the project:

using UnityEngine;
using System.Collections;
using UnityEngine.UI; //------------------------------ public class GameController : MonoBehaviour { //Game score public static int Score; //Prefix public string ScorePrefix = string.Empty;ic //Score text object public Text ScoreText = null; //Game ...

Get Unity 2018 By Example - Second Edition now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.