Question
How do I call an image of a button from Firebase with the same code, but make this code for a button instead of a
How do I call an image of a button from Firebase with the same code, but make this code for a button instead of a SpriteRenderer
c# code?
public class dataBase : MonoBehaviour { DatabaseReference reference;
void Start() { FirebaseApp.GetInstance("URL"); DatabaseReference reference = FirebaseDatabase.DefaultInstance.RootReference; StartCoroutine(retrieveData()); }
private IEnumerator loadUrl(string MediaUrl) { UnityWebRequest request = UnityWebRequestTexture.GetTexture(MediaUrl); yield return request.SendWebRequest(); if (request.isNetworkError || request.isHttpError) Debug.Log(request.error); else { Texture2D webTexture = ((DownloadHandlerTexture)request.downloadHandler).texture as Texture2D; Sprite webSprite = SpriteFromTexture2D(webTexture); gameObject.GetComponent
Sprite SpriteFromTexture2D(Texture2D texture) { return Sprite.Create(texture, new Rect(0.0f, 0.0f, texture.width, texture.height), new Vector2(0.5f, 0.5f), 100.0f); } //image from firebase to SpriteRenderer in unity private IEnumerator retrieveData() { var img = reference.Child("positionGame").Child("link").GetValueAsync();
yield return new WaitUntil(predicate: () => img.IsCompleted);
if (img != null) { StartCoroutine(loadUrl(img.Result.Value.ToString())); }
}
//image from firebase to button in unity....?
}
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started