https://s3-us-west-2.amazonaws.com/secure.notion-static.com/5cad8712-89d4-46fb-92dd-eff6e2c6c05d/Totoro.mp4

A button press enables a delightful experience (sound on)

Description:

By using serial communication between the Arduino and Unity, I created a mini scene that triggers different parameters once the button is hit.

Details:

By receiving the serial communication from the arduino – In the form of a number, I created this logic statement to detect when the button is pressed:

void OnMessageArrived(string msg) 
    {
        float speed = float.Parse(msg) * 100;
        if (float.Parse(msg) == 0) {
            // PLAY AUDIO
            audioSource.Play();
            // enable camera animator
            cam.enabled = true;
            cam.SetTrigger("Active");
            // this delays the lighting until the camera animation fineshes
            StartCoroutine(changeLighting());
        }
    }

There was also another challenge because I didn't want to have the lighting be enabled until a specific part of a song. In order to solve for that, I used the StartCoroutine() function in order to be able to use the WaitForSeconds() function.

The function is here:

IEnumerator changeLighting() {
      // DELAY AND CHANGE LIGHTING
      yield return new WaitForSeconds(11.500F);
      lighting.color = Color.white;
      anim.Play();
  }

Overall this process was very informative because I learned more about the different classes that I can manipulate via a script. I also gained a deeper understanding in how to get components and manipulate them as well.

Some of the principles that I learned from this project can be applied to future projects because I can now time certain triggers according to a delay and manipulate certain components whenever I want to.


Reflecting back to this process, could I have done the same thing without the Arduino and simply use the Unity Play Button? Probably. But why should I?