Saturday, December 17, 2016

Control an Animation Transition

This post covers transitioning an animation with a software event.  This post builds upon Importing an Animation into Unity.  The example below is based on having imported a model from Blender that already has two animations embedded in it (swim and idle).

This post will show how to setup a transition condition, and how to trigger it in code.

Looking first at the Animator Controller view, you'll see I've already added transitions between the Swim and Idle state.


Import Blender Animation

This post details how to get an animated model into Unity.  This post is built on post on a different blog which can be found here (if using blender): Multiple Animations in Blender.  Once you've created your model with built in animations, bring it into the Unity project.  In this example my model is called "TestRig".

The first step is to add an  Assets > Create > Animator Controller.  When you double click on it, you'll see a node-editing type view.


Friday, December 16, 2016

Google Cardboard Input

Successfully setting up input for Google Cardboard has a lot to do with applying scripts to the right place.  This post will cover what I've found to be the minimal set to get this working.

Please follow the setup steps in this Post as a prerequisite, as you'll need to have loaded the SDK package into your project, and added a GvrMain to your scene.

Setup the Scene

  1. On the GvrMain
    • Add the GvrPointerManager script
  2. On the Main Camera under the GvrMain
    1. Add the GvrPointerPhysicRaycaster script
    2. Add a GvrReticlePointer prefab as a child of the Main Camera
  3. Add an EventSystem to the scene
    1. Remove the StandaloneInputModule script
    2. Add the GvrPointerInputModule

Tuesday, December 13, 2016

Adding Background Sound (or Music)

Adding background (ambient noise) or perhaps music to your scene is a simple of matter of adding an Audio Source to your Main Camera.

If you camera object does not already have an Audio Listener, then you will need to add one.

In this way the sound will always be prevalent instead of based on how far or near you are to the source.

Add a Spatial Sound

Making use of the Google Cardboard SDK, you can add spatial sounds to your scene that react to head direction changes.

You can add a spatial sound in two ways:

  • Drag a GvrAudioSource prefab into your scene
  • Add the GvrAudioSource script to your object
Ensure that your project settings have the Audio value of Spatializer Plugin set to the GVR Audio Spatializer.

Edit > Project Settings > Audio


You also may have to enable the GvrAudioListener script that resides on the GvrMain > Head > MainCamera game object.  This is provided as a part of the prefab.

At this point, when you play your game, you should hear the sound (assuming the source is in range), and as you turn your head, you should hear the sound move accordingly.

Saturday, December 10, 2016

Google Cardboard Integration

Integration with Google Cardboard was not trivial, and I ran into several hiccups, but here is the process of getting Google Cardboard building and deployed with Unity (5.5.0f3)


  1. First install the Android Studio to get the Android SDK on your computer
  2. Next, download the Google VR SDK for Unity
  3. Create a new Unity Project
  4. Assets > Import Package > Custom Package
    1. Navigate to where you downloaded the Google VR SDK, select package
    2. Deselect the following
      1. Google VR > Demos
      2. Plugins > Android > gvr-permissionsupport-release.aar
      3. Plugins > iOS
    3. Click Import button
    4. Go Ahead with "API Update Required"
  5. There is at least one script with a compilation error
    1. Find the script error in the console, or just open GvrVideoPlayerTexture.cs
    2. Line 595 - add a "yield" before the "return false;"
  6. Allow extra import packages to be loaded "GVRBackwardsCompatibility"
  7. Delete the Main Camera
  8. Add a GvrMain prefab to your scene (this is your VR camera)
    1. Add other elements to your scene as desired
  9. File > Build Settings
    1. Select Android
    2. Player Settings > Identification > Bundle Identifier (update this field)
    3. Build
    4. When asked about Android 6.0 Platform requirements, click Continue
    5. If it complains about "Merging Android Manifests", you'll need to find the gvr-permissionsupport-release.aar file and manually delete it.

Friday, December 9, 2016

Debug and Deploy to Android

I'm excited that Unity's business model changed and now it is free to deploy to Android.

They have some very good Setup Instructions for debugging and deploying.

Some things to note:

  • In installing the Android Studio, my SDK was installing here:
    • C:\Users\**username**\AppData\Local\Android\android-sdk
  • Create a new project
  • Make sure to set the Bundle Identifier in:  
    • Update Player Settings > Other Settings > Bundle Identifier
If you want to Debug with your device, ensure it is connected via USB and click Build & Run.

If you want to deploy your game, just click Build.  This will produce an APK file which you can transfer to your device.

On your device, find the file in a file browser, select it, and when Android asks you if you want to install, say yes.  The game will launch and a generic icon will be added to your apps list.