Game controller

The role of the game controller is to keep score and other game-wide features. For now, we'll just keep score. Let's add that as follows:

  1. In the root of the Hierarchy, create an empty game object, name it GameController.
  2. And reset its Transform.
  3. In the Project Assetts/ARPlayBall/Scripts/ folder create a new C# script named GameController and drag it onto GameController as a component.

Open the GameController script for editing as follows:

File: GameController.csusing UnityEngine; using UnityEngine.UI; public class GameController : MonoBehaviour { public int hitPoints = 10; public int missPoints = -2; public BallGame ballGame; public Text scoreDisplay; private int playerScore; void Start() { ballGame.OnGoalWon.AddListener(WonGoal); ...

Get Augmented Reality for Developers 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.