public void OnRayCastSend(RayCastAndroidMessage msg) { Debug.Log("Image Target Name: " + msg.imageTargetName); Debug.Log("Camera's Position w.r.t Image Target: " + msg.cameraPosition); Debug.Log("Ray Direction in WorldSpace: " + msg.rayDirection); // trace the ray on the hololens here // Raycast against all GameObjects that are on spatial mesh int layerMask = 1 << LayerMask.NameToLayer("SpatialMesh"); //construct a Ray using the camera's position and tap direction Vector3 origin = msg.cameraPosition + this.gameObject.transform.position; Ray tapRay = new Ray(origin, msg.rayDirection); //Raycast using constructed Ray and store collisions in array hits RaycastHit[] hits = Physics.RaycastAll(tapRay, float.MaxValue, layerMask); string dm = ""; Vector3 tmpPos = new Vector3(0, 0, 0); if (hits.Length > 0) { foreach (RaycastHit hit in hits) { dm += string.Format("Hit Object **\"**{0}**\"** at position **\"**{1}**\"**", hit.collider.gameObject, hit.point); tmpPos = hit.point - this.gameObject.transform.position; } } else { dm += "Nothing was hit."; } // sends information back to the Android RayCastHololensMessage hololensMsg = new RayCastHololensMessage() { targetPosition = tmpPos, debugMsg = dm }; NetworkClient.Send(hololensMsg); }
public void OnRayCastReceive(RayCastHololensMessage msg) { // show the target in the right place here target.SetActive(true); target.transform.position = msg.targetPosition + this.gameObject.transform.position; }