BallGame component
Now is a good time to add the BallGame
component to our ball game.
The BallGame
component is associated with each separate ball game. It uses the ThrowControl
component to determine when the show is done and if the ball hit the goal. Then, it invokes a Won
or Lost
event accordingly.
We'll add a BallGame
component to our Boxball
game. When we add more games, such as basketball and football, they'll also have a BallGame
component:
- In the Project
Assets/ARBallPlay/Scripts/
folder, create a C# script namedBallGame
. - Add the component to the
BoxballGame
object. - And then open it for editing.
The full script is as follows:
File: BallGame.cs using UnityEngine; using UnityEngine.Events; public class BallGame : MonoBehaviour { public ThrowControl BallThrowControl; public GameObject CourtGameObject; public CollisionBehavior GoalCollisionBehavior; public UnityEvent OnGoalWon; public UnityEvent OnGoalLost; private bool wonGoal; void Start() { ...