我遇到一个问题,当用户选择该特定对象时,我试图访问静态成员以使该消息显示在数据库中。顺便说一下,我的前端正在统一使用它。因此,任何人都可以帮助我解决此问题。谢谢您的帮助。
这是我的代码:
public void NextButton()
{
if (highlightSet == true)
{
var httpWebRequest =
(HttpWebRequest) WebRequest.Create("https://PROJECT_URL.firebaseio.com/brokenComp.json");
httpWebRequest.ContentType = "application/json";
httpWebRequest.Method = "PUT";
using (var streamWriter = new StreamWriter(httpWebRequest.GetRequestStream()))
{
string missingObjectCount = TextDisplay.Message;
streamWriter.Write(missingObjectCount);
}
var httpResponse = (HttpWebResponse) httpWebRequest.GetResponse();
using (var streamReader = new StreamReader(httpResponse.GetResponseStream()))
{
var result = streamReader.ReadToEnd();
}
// When everything is Okay, it will load the scene.
SceneManager.LoadScene("Quiz");
}
else if (highlightSet == false)
{
Transform[] transforms = Selection.GetTransforms(SelectionMode.Deep |
SelectionMode.ExcludePrefab | SelectionMode.Editable);
if (transforms.Length > 0 &&
EditorUtility.DisplayDialog("Select a missing object",
"Please find the missing object "
+ "of the Headset", "", "OK"))
{
foreach (Transform transform in transforms)
{
RaycastHit hit;
if (Physics.Raycast(transform.position, -Vector3.up, out hit))
{
transform.position = hit.point;
Vector3 randomized = Random.onUnitSphere;
randomized = new Vector3(randomized.x, 0F, randomized.z);
transform.rotation = Quaternion.LookRotation(randomized, hit.normal);
}
}
}
}
}
TextDisplay:
public class TextDisplay: MonoBehaviour
{
public static string Message;
}
OBClick:
public void OnPointerClick(PointerEventData eventData)
{
if (!BlowupController.RemoveStatus)
{
EventSystem eventSystem = EventSystem.current;
var RIM = (ReticleInputModule)eventSystem.gameObject.GetComponent(typeof(ReticleInputModule));
GameObject tmp = GameObject.Find("Reticle Text");
var ob = (TextDisplay)gameobj.GetComponent(typeof(TextDisplay));
if (tmp == null)
{
GameObject TextGO = new GameObject("Reticle Text");
Text txt = TextGO.gameObject.AddComponent<Text>();
// txt.text = ob.Message;
txt.text = TextDisplay.Message;
txt.font = Resources.GetBuiltinResource(typeof(Font), "Arial.ttf") as Font;
txt.fontSize = 20;
txt.color = Color.white;
txt.alignment = TextAnchor.MiddleCenter;
TextGO.transform.SetParent(RIM.reticle.transform);
TextGO.transform.localPosition = new Vector3(0f, -80f, -1.2f);
TextGO.transform.localScale = new Vector3(1f, 1f, 1f);
TextGO.transform.localRotation = new Quaternion(0f, 0f, 0f, 0f);
RectTransform rt = TextGO.GetComponent(typeof(RectTransform)) as RectTransform;
rt.sizeDelta = new Vector2(500, 30);
}
else
{
Text txt = tmp.GetComponent<Text>();
// txt.text = ob.Message;
txt.text = TextDisplay.Message;
}
}
else
{
BlowupController.UndoList.Add(gameobj);
gameobj.SetActive(false);
}
}
}
如果您从Web请求中收到404错误,这是因为Firebase无法找到您请求的资源。确保您的URL(https://PROJECT_URL.firebaseio.com/brokenComp.json
)是正确的。