Short lecture on Unity and how to use Unity and SteamVR to create a simple VR scene. Taught by Mark Billinghurst at the University of South Australia on July 30th 2019
9. Unity 3D features
• Cross platform
• Windows, OSX, iOS, Android, Linux, WebGL, etc.
• Fast rapid development
• Visual scene assembly, rapid prototyping
• Control over rendering pipeline
• Access to low level graphics, shader programming
• Scripting in multiple coding languages
• C#, C++, Javascript, etc.
• Asset store with thousands of contributions
• Models, behaviours, programming tools, etc.
• Very large developer/support community
20. Building Scenes
• Use GameObjects:
• Containers that hold different components
• Eg 3D model, texture, animation
• Use Inspector
• View and edit object properties and other settings
• Use Scene View
• Position objects, camera, lights, other GameObjects etc
• Scripting
• Adding interaction, user input, events, etc
21. GameObjects
• Every object in Scene is a GameObject
• GameObjects contain Components
• e.g. Transform Component, Camera Component
22. Adding 3D Content
• Create 3D asset using modeling package, or download
• Fbx, Obj file format for 3D models
• Add file to Assets folder in Project
• When project opened 3D model added to Project View
• Drag mesh from Project View into Hierarchy or Scene View
• Creates a game object
30. Making a Simple Scene
1. Create New Project
2. Create Game Object
3. Moving main camera position
4. Adding lights
5. Adding more objects
6. Adding physics
7. Changing object materials
8. Adding script behaviour
37. Add More Objects
• Add several cubes
• GameObject -> 3D Object – Cube
• Move cube
• Add Rigid Body component (uncheck gravity)
38. Add Material
• Assets -> Create -> Material
• Click Albedo colour box in inspector
• Select colour
• Drag asset onto object to apply
39. Add Script
• Assets -> Create -> C# script
• Edit script using Mono/Visual Studio
• Drag script onto Game Object
40. Example C# Script
GameObject Rotation
using UnityEngine;
using System.Collections;
public class spin : MonoBehaviour {
// Use this for initialization
void Start () {
}
// Update is called once per frame
void Update () {
this.gameObject.transform.Rotate(Vector3.up*10);
}
}
41. Scripting C# Unity 3D
• void Awake():
• Is called when the first scene is loaded and the game object is active
• void Start():
• Called on first frame update
• void FixedUpdate():
• Called before physics calculations are made
• void Update():
• Called every frame before rendering
• void LateUpdate():
• Once per frame after update finished
43. Resources
• Unity Main site
• https://unity.com/
•Holistic Development with Unity
• http://holistic3d.com
• Official Unity Tutorials
• https://learn.unity.com/
•Unity Coder Blog
• http://unitycoder.com
52. Basic Scene Setup
• Create a new scene and delete Main Camera
• Add player prefab to the scene
• Assets -> SteamVR -> InteractionSystem -> Core -> Prefab -> Player
53. Add Scene Content
• Create a ground plane
• GameObject -> 3D object -> Plane
• Place several objects
• GameObject -> 3D object -> Cube
54. Run Scene
• In HMD you should see two controllers
• Scene reacts as you move your head
55. Setting up Teleport
• Drag teleport pre-fab to scene hierachy
• Assets -> InteractionSystem -> Teleport -> Prefabs
• Add teleport plane to set up teleport area (Set y value to 0.01)
• GameObject -> 3D object -> Plane
• Drag teleport area script to teleport plane
• Assets -> InteractionSystem -> Teleport -> Scripts-> TeleportArea
57. Interactions Demo
• Load sample interactions scene
• Assets/SteamVR/InteractionSystem/ ->
Samples/Scenes/Interactions_Example.unity
• Setup SteamVR Input (first time run)
• Hit save and generate to create input bindings
• NOTE: video here www.youtube.com/watch?v=qo-9CmcKWlY
58. Features
• Wide range of user interactions
• Throwing, Grabbing, Remote control
• Teleportation, Different hand styles
• Live input data
60. Software
• Unity 2018.4.5f1, latest version of Unity with long term
support. Works with SteamVR and VRTK.
• https://unity3d.com/unity/whats-new/2018.4.5
• SteamVR HTC Vive Tutorial
• https://www.raywenderlich.com/9189-htc-vive-tutorial-
for-unity
• Getting Started with VRTK
• https://vrtoolkit.readme.io/docs/getting-started
61. Ray Wenderlich Tutorials
• Excellent set of step by step tutorials
• www.raywenderlich.com
• Introduction to Unity: Getting Started
• www.raywenderlich.com/772-introduction-to-unity-getting-started-part-1-2
• Introduction to Unity Scripting
• www.raywenderlich.com/980-introduction-to-unity-scripting
• HTC Vive Tutorial for Unity
• www.raywenderlich.com/9189-htc-vive-tutorial-for-unity
63. Google Poly for 3D models
• https://poly.google.com/
• Repository of user contributed low polygon objects
• Free to download for AR/VR applications