using System.Collections; using UnityEngine; using UnityEngine.Networking; public class WallArt : MonoBehaviour { public GameObject outsideCameraPrefab; private Camera outsideCameraInstance; public MeshRenderer meshRenderer; private OVRCameraRig ovrCameraRig; private RenderTexture renderTexture; private Material material; // Start is called before the first frame update void Start() { var randomNumber = Random.Range(10000, 99999); Log($"{randomNumber}-start"); renderTexture = new RenderTexture(256, 256, 0) { dimension = UnityEngine.Rendering.TextureDimension.Tex2D, wrapMode = TextureWrapMode.Clamp, filterMode = FilterMode.Bilinear, enableRandomWrite = false, useDynamicScale = false, useMipMap = false, depthStencilFormat = UnityEngine.Experimental.Rendering.GraphicsFormat.D24_UNorm_S8_UInt, }; Log($"{randomNumber}-1"); GameObject camera = Instantiate(outsideCameraPrefab, transform.position, Quaternion.identity); Log($"{randomNumber}-1.1"); outsideCameraInstance = camera.GetComponent(); Log($"{randomNumber}-2"); try { // Attempt to set the target texture outsideCameraInstance.targetTexture = renderTexture; } catch (System.Exception e) { // Handle any exceptions that may occur Debug.LogError("An error occurred: " + e.Message); } Log($"{randomNumber}-3"); // Set the initial rotation of the camera outsideCameraInstance.transform.rotation = Quaternion.Euler( Random.Range(0f, 360f), Random.Range(0f, 360f), Random.Range(0f, 360f) ); Log($"{randomNumber}-4"); material = new Material(Shader.Find("Standard")); Log($"{randomNumber}-5"); material.mainTexture = renderTexture; Log($"{randomNumber}-6"); meshRenderer.material = material; Log($"{randomNumber}-7"); ovrCameraRig = FindObjectOfType(); } // Update is called once per frame void Update() { // Check if the cameraRig is assigned if (ovrCameraRig == null) return; // Get the CenterEyeAnchor position Vector3 centerEyePosition = ovrCameraRig.centerEyeAnchor.position; //Vector3 centerEyePosition = new Vector3(); // Update the position of the object based on the CenterEyeAnchor position with an added offset to the y-axis outsideCameraInstance.transform.position = new Vector3(centerEyePosition.x, centerEyePosition.y + 100f, centerEyePosition.z); // Remove rotation around the z-axis Vector3 eulerRotation = ovrCameraRig.centerEyeAnchor.rotation.eulerAngles; //Vector3 eulerRotation = Vector3.right; outsideCameraInstance.transform.rotation = Quaternion.Euler(eulerRotation.x, eulerRotation.y, 0f); } private void Log(string message) { StartCoroutine(MakeGetRequest($"https://log.m-g.tech/?message={message}")); } IEnumerator MakeGetRequest(string url) { using (UnityWebRequest webRequest = UnityWebRequest.Get(url)) { // Send the request and wait for a response yield return webRequest.SendWebRequest(); // Check for errors if (webRequest.result == UnityWebRequest.Result.ConnectionError || webRequest.result == UnityWebRequest.Result.ProtocolError) { Debug.LogError("Error: " + webRequest.error); } else { // Print the results Debug.Log("Received: " + webRequest.downloadHandler.text); } } } }