// Tap event listener private void TapRecognizer_TappedEvent(InteractionSourceKind source, int tapCount, Ray headRay) { // Drops brick on even taps if (odd_tap == false) { // Stops registering tap events to provent spawning new bricks before server message is sent tapRecognizer.StopCapturingGestures(); // Changes property of active_brick to freeze_object so it nolonger follows the camera freeze_object = active_brick; active_brick = null; // Accesses the rigid body components of the freeze_object game object and enables gravity so object falls rb = freeze_object.GetComponent <Rigidbody>(); rb.useGravity = true; // Set odd_tap to true so next tap spawns a new brick odd_tap = true; // Executes custom _freeze method 0.5 seconds after fall, so it has plenty of time to reach the ground Invoke("_freeze", 0.5f); // Posts the position and rotation information to the server networking.MainAsync( posX, posY, posZ, rotX, rotY, rotZ); // Write the position and rotation information into local text file writeTextHelper.WriteString( posX, posY, posZ, rotX, rotY, rotZ); } // Creates brick on odd taps else { // Initializes brick model to starting position and default rotation var newBrickPosition = new Vector3(0f, 0.65f, -2f); GameObject NewBrick = Instantiate(brick_prefab, newBrickPosition, Quaternion.identity); // Tags the brick for easy grouping NewBrick.tag = "brick"; var rb = NewBrick.GetComponent <Rigidbody>(); // Sets rigid body properties for the brick while it's controlled by viewer's camera if (rb == null) { return; } // Removes the effect of gravity rb.useGravity = false; // Removes velocity rb.velocity = Vector3.zero; // Set desired brick rotation rb.rotation = Quaternion.Euler(-90f, 0f, 0f); // Fixes the rotation and only allow translation rb.freezeRotation = true; // Assigning counts to the bricks array, to make it easier to access the most recent brick. bricks[count] = NewBrick; count += 1; // Sets NewBrick as active_brick which follows the camera movements active_brick = NewBrick; odd_tap = false; } }