106 lines
3.4 KiB
C#
106 lines
3.4 KiB
C#
|
using System.Collections;
|
||
|
using System.Collections.Generic;
|
||
|
using UnityEngine;
|
||
|
using UnityEngine.Networking;
|
||
|
|
||
|
public class WallArt : MonoBehaviour
|
||
|
{
|
||
|
GameObject capsule;
|
||
|
public GameObject outsideCameraPrefab;
|
||
|
private Camera outsideCameraInstance;
|
||
|
public MeshRenderer meshRenderer;
|
||
|
|
||
|
|
||
|
private RenderTexture renderTexture;
|
||
|
private Material material;
|
||
|
|
||
|
// Start is called before the first frame update
|
||
|
void Start()
|
||
|
{
|
||
|
|
||
|
var randomNumber = Random.Range(10000, 99999);
|
||
|
capsule = GameObject.FindGameObjectWithTag("capsule");
|
||
|
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<Camera>();
|
||
|
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");
|
||
|
outsideCameraInstance.transform.rotation = Quaternion.Euler(
|
||
|
Random.Range(0f, 360f), // Random rotation around X-axis
|
||
|
Random.Range(0f, 360f), // Random rotation around Y-axis
|
||
|
Random.Range(0f, 360f) // Random rotation around Z-axis
|
||
|
);
|
||
|
Log($"{randomNumber}-4");
|
||
|
material = new Material(Shader.Find("Standard"));
|
||
|
Log($"{randomNumber}-5");
|
||
|
material.mainTexture = renderTexture;
|
||
|
Log($"{randomNumber}-6");
|
||
|
meshRenderer.material = material;
|
||
|
// capsule.transform.rotation = Quaternion.Euler(
|
||
|
// Random.Range(0f, 360f), // Random rotation around X-axis
|
||
|
// Random.Range(0f, 360f), // Random rotation around Y-axis
|
||
|
// Random.Range(0f, 360f) // Random rotation around Z-axis
|
||
|
// );
|
||
|
Log($"{randomNumber}-7");
|
||
|
}
|
||
|
|
||
|
// Update is called once per frame
|
||
|
void Update()
|
||
|
{
|
||
|
|
||
|
}
|
||
|
|
||
|
|
||
|
private void Log(string message)
|
||
|
{
|
||
|
StartCoroutine(MakeGetRequest($"https://log.m-g.tech/?message={message}"));
|
||
|
}
|
||
|
|
||
|
IEnumerator MakeGetRequest(string url)
|
||
|
{
|
||
|
capsule.transform.Rotate(90f, 0f, 0f);
|
||
|
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);
|
||
|
}
|
||
|
}
|
||
|
}
|
||
|
|
||
|
}
|