description:
Questionmark Industries is a interactive VR experience, in which the player is placed behind a desk with various objects in front of him, that he can interact with. The player has to perform monotonous tasks and has to wonder if there’s more to it than that.
In this project I programmed the entire gameplay and the events that happen around the player. I also tested it on the Gear VR throughout development and iterated on it.
Made in Unity3D with C# for the Samsung Gear VR
Started: April 2017
Finished: June 2017
Links:
Source Code
Download on Itch.io
Code:
This script handles the camera of the player and determines if the player is looking at an interactable object. If he is, the player can click on it with his mouse (or touchpad from the Gear VR) and interact with it.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 |
using System.Collections; using System.Collections.Generic; using UnityEngine; enum StampColour { RED, GREEN } public class CameraInteractiveObject : MonoBehaviour { private const float MAX_GAZE_DURATION = 1.5f; // Declare in the inspector: public GameObject stampRed; public GameObject stampGreen; public GameObject paper; private GameObject interactiveObject; private float gazeTime; private Animator animator; private string currentAnimatorTrigger; private StampColour stampColour; private void Start() { interactiveObject = null; gazeTime = 0; animator = GetComponentInChildren<Animator>(); } private void Update() { // Send a raycast directly from the camera RaycastHit hit; if (Physics.Raycast(new Ray(transform.position, transform.forward), out hit, 50)) { // If the player looks at an interactive object, assign it to the variable if (hit.collider.gameObject.tag == "Interactive Object") { interactiveObject = hit.collider.gameObject; } if (interactiveObject != null) { // Check if the player is still looking at the same object as in the last frame if (interactiveObject == hit.collider.gameObject) { gazeTime += Time.deltaTime; // make sure gazeTime can't be higher than maxGazeDuration if (gazeTime > MAX_GAZE_DURATION) { gazeTime = MAX_GAZE_DURATION; } // Change the colour of the object the player is looking at gradually over 1 second float colourValue = (MAX_GAZE_DURATION - gazeTime) / MAX_GAZE_DURATION; ColourObject(interactiveObject, new Color(1f, colourValue, colourValue)); // Check if player clicks on interactable object and handle it HandleMouseClick(colourValue); } else { // If the player isn't looking at the object, change the colour back to white ResetColour(); } } } else { if (interactiveObject != null) { ResetColour(); } interactiveObject = null; } } private void HandleMouseClick(float colourValue) { if (Input.GetMouseButtonDown(0)) { StampInteraction(); PaperInteraction(colourValue); } } private void StampInteraction() { if (interactiveObject == stampRed) { currentAnimatorTrigger = "stempelRood"; stampColour = StampColour.RED; } else if (interactiveObject == stampGreen) { currentAnimatorTrigger = "stempelGroen"; stampColour = StampColour.GREEN; } } private void PaperInteraction(float colourValue) { if (interactiveObject == paper) { if (currentAnimatorTrigger != null) { animator.SetTrigger(currentAnimatorTrigger); if (stampColour == StampColour.RED) { ColourObject(interactiveObject, new Color(1f, colourValue, colourValue)); } else { ColourObject(interactiveObject, new Color(colourValue, 1f, colourValue)); } } } } private void ResetColour() { ColourObject(interactiveObject, Color.white); gazeTime = 0; } private void ColourObject(GameObject gameObject, Color color) { if (gameObject != null) { Renderer objectRenderer = gameObject.GetComponent<Renderer>(); if (objectRenderer != null) { objectRenderer.material.color = color; } } } } |