Now we're ready to implement the meat of our game. When the trigger is pressed, the controller script creates a new balloon by instantiating the Balloon prefab in the scene. When the trigger is released, the balloon object is permitted to float up into the sky. And while the button is held, we'll grow (inflate) the balloon's scale. Let's begin.
Creating balloons
The BalloonController.cs script should nowcreate a new balloon when the trigger button gets pressed. In your code editor, change theUpdatefunction to the following:
void Update()
{
if (Input.GetButtonDown("XRI_Right_TriggerButton"))
{
CreateBalloon();
}
}
We need to write this CreateBalloon() function. It will reference the Balloon prefab that we created earlier in this chapter and create a new instance of it in the scene. So first, declare a public GameObject variable named balloonPrefab...