top of page

Timers & Buttons - Making My First Holograms

Let's start with some timers & buttons.


Here's a video of the timer holograms I made in Unity:


The timer's features:



Countdown (C#)

 

Now for the script that controls the timer, Timer_20.cs:

  • This was my first script with C#

using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using TMPro;

//Timer Script by Katie Gonsoulin

public class Timer_20 : MonoBehaviour
{
    bool timerReset = false;
    bool timerActive = false;
    public float timeValue = 1200;
    public TextMeshPro timerText;

    // Update is called once per frame
    void Update()
    {
        if (timerActive == true)
        {
            if (timeValue > 0)
            {
                //subtract 1 second per frame
                timeValue -= Time.deltaTime;
            }
            else
            {
                timeValue = 1200;
                timerActive = false;
            }
            DisplayTime(timeValue);
        }
        if (timerReset == true)
        {
            //reset timeValue to default
            timeValue = 1200;
            DisplayTime(timeValue);
            timerActive = false;
            timerReset = false;
        }
    }

    void DisplayTime(float timeToDisplay)
    {
        if(timeToDisplay < 0)
        {
            //if time is < 0, display 0
            timeToDisplay = 0;
        }

        //algorithm to display time in minutes and seconds
        float minutes = Mathf.FloorToInt(timeToDisplay / 60);
        float seconds = Mathf.FloorToInt(timeToDisplay % 60);

        timerText.text = string.Format("{0:00}:{1:00}", minutes, seconds);
    }

    public void StartTimer()
    {
        timerActive = true;
    }

    public void StopTimer()
    {
        timerActive = false;
    }

    public void ResetTimer()
    {
        timerReset = true;
    }
}


Buttons

 

Here's the Unity architecture for the timer's buttons:



Here are the buttons' components:

  • pay special attention to the components Box Collider and NearInteractionTouchable every hologram in the program needs to have these to be functional in an AR environment








Connection to the Bluetooth lighting system

 

The timer's purpose is to notify the user when a resin layer is set. Once the time runs out, the Bluetooth-connected lighting system would wipe green in case the user removes the HoloLens 2 headset (which we recommended every ~30 minutes because it gets uncomfortably warm).


Here is how the finished lighting-control buttons look in augmented reality:


bottom of page