Jesse Sperling
Published © GPL3+

I Don't Wanna Miss A Thing

Using hidden triggers around 360° video, we pause the action depending on where the viewer looks so they don't miss important details.

BeginnerProtip631
I Don't Wanna Miss A Thing

Things used in this project

Software apps and online services

Unity
Unity
AutoPano Video Pro

Story

Read more

Code

Video Controller

C#
Attach this to you projection sphere. This allows your video to play at the beginning of your program, loop throughout and be paused based on camera movement.
using UnityEngine;
using System.Collections;

public class VideoController : MonoBehaviour {


	private bool check;

	void Awake () {
		MovieTexture movie = GetComponent<Renderer>().material.mainTexture as MovieTexture;
		movie.loop = true;
		movie.Play ();
	
	}
	
	void Update () {
		GameObject mainCamera = GameObject.Find("Main Camera");
		MainCamera cameraScript = mainCamera.GetComponent<MainCamera> ();
		check = cameraScript.isLookingAway;

		MovieTexture movie = GetComponent<Renderer>().material.mainTexture as MovieTexture;

		if (!check) {
			movie.Play ();
		} else {
			movie.Pause ();
		}
	}
}

Main Camera

C#
This script attaches to your Main Camera. It projects the Raycast and creates the bool that pauses and plays our video in VideoController.
using UnityEngine;
using System.Collections;

public class MainCamera : MonoBehaviour {
	public bool isLookingAway;

	void Update () {
		RaycastHit hit;
		Ray ray = gameObject.GetComponent<Camera>().ViewportPointToRay(new Vector3(0.5f, .5f, 0));

		Debug.DrawRay(ray.origin, ray.direction * 300, Color.yellow);

		if (Physics.Raycast (ray, out hit) && hit.transform.tag == "Trigger") 
		{
			isLookingAway = false;
		} 
		else 
		{
			isLookingAway = true;
		}
	}
}

Reverse Normals

C#
This script attaches to your projection sphere and reverses its normals so that your video faces inward to be viewed by our camera.
using UnityEngine;
using System.Collections;

[RequireComponent(typeof(MeshFilter))]
public class ReverseNormals : MonoBehaviour {

	void Start () {
		MeshFilter filter = GetComponent(typeof (MeshFilter)) as MeshFilter;
		if (filter != null)
		{
			Mesh mesh = filter.mesh;

			Vector3[] normals = mesh.normals;
			for (int i=0;i<normals.Length;i++)
				normals[i] = -normals[i];
			mesh.normals = normals;

			for (int m=0;m<mesh.subMeshCount;m++)
			{
				int[] triangles = mesh.GetTriangles(m);
				for (int i=0;i<triangles.Length;i+=3)
				{
					int temp = triangles[i + 0];
					triangles[i + 0] = triangles[i + 1];
					triangles[i + 1] = temp;
				}
				mesh.SetTriangles(triangles, m);
			}
		}		
	}
}

Credits

Jesse Sperling
1 project • 0 followers

Comments