I am trying to create a singleton that downloads textures from the web. but whenever I pass URL to singleton through the external script I get an error saying an object is not set to Instance of an object at line below:
WebImage.instance.url = imageURL;
Below is an implementation of the singleton.
public static WebImage instance;
[SerializeField] public string url;
[SerializeField] public Texture2D texture;
private void Awake()
{
if (instance != null)
{
Destroy(this.gameObject);
return;
}
instance = this;
DontDestroyOnLoad(this.gameObject);
}
Below is an implementation of another GetImage
script in which I am sending the URL to the above singleton.
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class GetImage : MonoBehaviour
{
[SerializeField] List<Texture2D> Textures;
[SerializeField] public string imageURL = "https://arqosh.s3.ap-south-1.amazonaws.com/images/0.5046188924886419-images%20(1).jfif";
[SerializeField] Texture2D texture;
void Awake()
{
**WebImage.instance.url = imageURL;** // error here saying object is not set to an instance of object.
texture = WebImage.instance.texture;
}
}