I am having issues with black screen when running the emulation mode or simulator for Microsoft hololens. In the preview the camera shows what the user should see. I see no obvious reason to behave like this and no error/warning is given. I am using code snippets from the Origami tutorial,except I chose to use RayCastNonAlloc.
Movement.cs
public class Movement : MonoBehaviour {
public GameObject person;
public float seconds;
private Vector3 point = new Vector3(0,0,0);
private RaycastHit[] rayHit = new RaycastHit[5];
void OnSelect()
{
person.transform.position = Vector3.Lerp(person.transform.position, point, seconds * Time.deltaTime);
}
// Update is called once per frame
void Update()
{
if (Physics.RaycastNonAlloc(Camera.main.transform.position, Camera.main.transform.forward, rayHit, Mathf.Infinity, ~0) > 0)
{
foreach (RaycastHit hit in rayHit)
{
point.x = Mathf.Clamp(hit.point.x, -290f, 6970f);
point.y = Mathf.Clamp(hit.point.y, -40f, 1860f);
point.z = Mathf.Clamp(hit.point.z, -1700f, 140f);
}
}
}
}`
Scene.cs
using UnityEngine; using UnityEngine.XR.WSA.Input; public class Scene : MonoBehaviour
{
public GameObject cursor;
public GameObject Focused { get; private set; }
public Scene Instance { get; private set; }
private GestureRecognizer recognizer;
private MeshRenderer Renderer;
private readonly RaycastHit[] rayHit = new RaycastHit[5];
void Awake()
{
Instance = this;
recognizer = new GestureRecognizer();
recognizer.Tapped += (args) =>
{
if (Focused != null)
{
Focused.SendMessageUpwards("OnSelect", SendMessageOptions.DontRequireReceiver);
}
};
recognizer.StartCapturingGestures();
Renderer = cursor.GetComponent<MeshRenderer>();
}
void Update()
{
GameObject oldFocused = Focused;
if (Physics.RaycastNonAlloc(Camera.main.transform.position,Camera.main.transform.forward,rayHit,Mathf.Infinity,~0)>0)
{
Renderer.enabled = true;
foreach ( RaycastHit hit in rayHit)
{
cursor.transform.position = hit.point;
cursor.transform.rotation = Quaternion.FromToRotation(Vector3.up, hit.normal);
Focused = hit.collider.gameObject;
}
}
else
{
Focused = null;
Renderer.enabled = false;
}
if (Focused != oldFocused)
{
recognizer.CancelGestures();
recognizer.StartCapturingGestures();
}
}
}