O'Reilly logo

Virtual Reality Blueprints by John Williamson, Charles Palmer

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Scripting the Milk Bottle Toss game

The script for this game is very simple and basic in nature. Without a scoring mechanism or need for a state machine, the script is just a shell to house the reset function.

While the game is running, the script listens for the Touch Controller's B or Y buttons. If either of these are pushed, the script destroys the balls and bottles from the scene and replaces them with new prefabs. It is a very fast solution which is easy to follow:

  1. Open the BottleGameController script and edit it to match the following. The script starts by setting variables for the prefabs and the transforms:
using System.Collections;using System.Collections.Generic;using UnityEngine; public class BottleGameController : MonoBehaviour ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required